Last active
June 20, 2019 08:36
-
-
Save motrdevua/dc5e0e90f983e5b8c1500953e0c88c82 to your computer and use it in GitHub Desktop.
Statistic counter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Statistics counter | |
$(window).on('scroll', function() { | |
let a = 0; | |
const parentOffset = | |
$('.stats__counters').offset().top - window.innerHeight + 100; | |
if (a === 0 && $(window).scrollTop() > parentOffset) { | |
$('.stats__count').each(function() { | |
const $this = $(this); | |
const countTo = $this.attr('data-count'); | |
$({ | |
countNum: $this.text(), | |
}).animate( | |
{ | |
countNum: countTo, | |
}, | |
{ | |
duration: 3000, | |
easing: 'swing', | |
step() { | |
$this.text(Math.floor(this.countNum)); | |
}, | |
complete() { | |
$this.text(this.countNum); | |
}, | |
} | |
); | |
}); | |
a = 1; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment