bfintal / Counter-Up2

Counter-Up is a lightweight module that counts up to a targeted number when the number becomes visible.
MIT License
196 stars 65 forks source link

How to use it simple or with jquery ? #2

Open yourchoice opened 5 years ago

yourchoice commented 5 years ago

How to use it simple or with jquery ?

counterUp( document.querySelector('.counter_number1'), { duration: 1000, delay: 16 } );

I have this error: Uncaught TypeError: counterUp is not a function

I use it with jquery and bootstrap 4 libs.

BhaveshSGupta commented 5 years ago

@bfintal, I was kind of trying to say same thing in #1. In other words can we have a demo which doesn't require any server-side stuff because currently many are using https://github.com/bfintal/Counter-Up with jquery. If needed I can help you with something.

esrat71 commented 5 years ago

i am getting confused how to initialized it in script ? can anyone help me

vuminhluan commented 5 years ago

Allow me. https://github.com/bfintal/Counter-Up2/blob/master/index.js

Andrew-Cottrell commented 5 years ago

For https://github.com/bfintal/Counter-Up2/releases/tag/v1.0.1, extract the dist/index.js file (ECMAScript 5 compatible), rename to counterup2-1.0.1.min.js, and use the following

jQuery(function ($) { // using failsafe $ alias here, see https://api.jquery.com/jQuery/#jQuery3
    "use strict";

    var counterUp = window.counterUp["default"]; // import counterUp from "counterup2"

    var $counters = $(".counter"); // see https://api.jquery.com/jQuery/#jQuery1

    /* Start counting, do this on DOM ready or with Waypoints. */
    $counters.each(function (ignore, counter) { // see https://api.jquery.com/each/
        counterUp(counter, {
            duration: 1000,
            delay: 16
        });
    });

});
jkdoyle commented 5 years ago

Not working for me.

Andrew-Cottrell commented 5 years ago

@jkdoyle Did you see any error in the console? Does window.counterUp look like the following?

> console.dir(window.counterUp)
▼ Module
    decimalPlaces: (...)
 ▶ default: ƒ (t)
    divideNumbers: (...)
    hasComma: (...)
    isFloat: (...)
    Symbol(Symbol.toStringTag): "Module"
    __esModule: true
 ▶ get decimalPlaces: ƒ ()
 ▶ get divideNumbers: ƒ ()
 ▶ get hasComma: ƒ ()
 ▶ get isFloat: ƒ ()
    __proto__: Object
emranweb commented 5 years ago

Please make jquery compatibility to easy uses.

markcnunes commented 5 years ago

Andrew-Cottrell's suggestion works fine for me. Here is an example with Waypoint: e.g: Codepen: CounterUp2 + Jquery + Waypoint

thinkvisual commented 5 years ago

Andrew-Cottrell's suggestion works fine for me also.

andriiomelchuk commented 4 years ago

Hi Andrew. Does your library work with jquery 3+?

Andrew-Cottrell commented 4 years ago

@yargohor

Hi Andrew. Does your library work with jquery 3+?

It is not my library; I merely commented above how I used Counter-Up2 with jQuery.

Counter-Up2 does appear to work with jQuery 3.4.1, but you would need to ask @bfintal for an authoritative answer.

debrajhyper commented 4 years ago

For https://github.com/bfintal/Counter-Up2/releases/tag/v1.0.1, extract the dist/index.js file (ECMAScript 5 compatible), rename to counterup2-1.0.1.min.js, and use the following

jQuery(function ($) {
    "use strict";

    var counterUp = window.counterUp["default"]; // import counterUp from "counterup2"

    var $counters = $(".counter");

    /* Start counting, do this on DOM ready or with Waypoints. */
    $counters.each(function (ignore, counter) {
        counterUp(counter, {
            duration: 1000,
            delay: 16
        });
    });

});

can I include Waypoints.js?

Andrew-Cottrell commented 4 years ago

can I include Waypoints.js?

@markcnunes has kindly provided an example with Waypoint.