admin管理员组

文章数量:1387286

I tried to use countup.js - I used it several times in the past, but now it is not working anymore. Does anybody see the mistake?

HTML:

<div id="counter">1000</div>

JS:

  function countup() {
    var options = {
      useEasing: true,
      useGrouping: true,
      separator: '.',
      decimal: ',',
      suffix: 'People'
    };

    var demo = new CountUp('counter', 0, $("#counter").text(), 2, 4, options);
    if (!demo.error) {
      demo.start();
    } else {
      console.error(demo.error);
    }
  }

countup();

Here is the codepen:

I tried to use countup.js - I used it several times in the past, but now it is not working anymore. Does anybody see the mistake?

HTML:

<div id="counter">1000</div>

JS:

  function countup() {
    var options = {
      useEasing: true,
      useGrouping: true,
      separator: '.',
      decimal: ',',
      suffix: 'People'
    };

    var demo = new CountUp('counter', 0, $("#counter").text(), 2, 4, options);
    if (!demo.error) {
      demo.start();
    } else {
      console.error(demo.error);
    }
  }

countup();

Here is the codepen: https://codepen.io/anon/pen/PrGvvK

Share Improve this question edited Jun 19, 2019 at 8:51 Maximilian Neuse asked Jun 19, 2019 at 8:47 Maximilian NeuseMaximilian Neuse 1631 gold badge5 silver badges15 bronze badges 4
  • 1 Check the console in your Codepen, there's several issues – Rory McCrossan Commented Jun 19, 2019 at 8:48
  • 1 Also, your not actually successfully importing the CountUp library... – Alicia Sykes Commented Jun 19, 2019 at 8:51
  • @RoryMcCrossan Unfortunalety I have no idea how to solve these problems. – Maximilian Neuse Commented Jun 19, 2019 at 8:52
  • @Alicia what is wrong? I added them via external scripts? – Maximilian Neuse Commented Jun 19, 2019 at 8:53
Add a ment  | 

2 Answers 2

Reset to default 3

add countUp.js in your Code:

  <script src='https://cdnjs.cloudflare./ajax/libs/countup.js/1.8.2/countUp.min.js'></script>

Working Demo

In your codepen example you are using version 2.0.4 (https://cdnjs.cloudflare./ajax/libs/countup.js/2.0.4/countUp.min.js) which uses ES6 code. You can see the error message in console.

Uncaught SyntaxError: Unexpected token export

browsers doesn't have full ES6 support. So if you use version 1.8.2 which doesn't use ES6 code it will work via external script.

Below is the codepen using older version

https://codepen.io/anon/pen/dBpxbd

本文标签: javascriptCountUpjs not starting to count upStack Overflow