1

I have this animated counter and it is working fine. But I want to know what is the type of this selector and what is its role in the code. https://jsfiddle.net/jdL2px4a/3/

$(window).scroll(function () {
    var oTop = $(".counter").offset().top;
    if ($(window).scrollTop() > oTop) {
        $(".count").each(function () {
            var $this = $(this);
            var val = $(this).attr("data-count");
            $({ counter: 0 }).animate({ counter: val }, {
                duration: 1000,
                easing: 'swing',
                step: function () {
                    $this.text(Math.ceil(this.counter));
                }
            });
       });
    }
});
Momo
  • 59
  • 1
  • 5
  • 5
    It's not a selector. It's placing an object in to a jQuery object and using a quirk of the library to use the `animate()` method to increment the `counter` property value every second and set it as the `text()` of the `.count` element – Rory McCrossan Sep 09 '19 at 13:31
  • 1
    https://stackoverflow.com/questions/28320881/please-explain-the-meaning-of-deg-0-in-jquery – Leved Resu Sep 09 '19 at 13:43
  • Counter is getting it's value from the `data-count` attribute of each `.count` elements. – K.G. Sep 09 '19 at 14:13

0 Answers0