Skip to content

Instantly share code, notes, and snippets.

@motrdevua
Last active June 20, 2019 08:36
Show Gist options
  • Save motrdevua/dc5e0e90f983e5b8c1500953e0c88c82 to your computer and use it in GitHub Desktop.
Save motrdevua/dc5e0e90f983e5b8c1500953e0c88c82 to your computer and use it in GitHub Desktop.
Statistic counter
// 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