Answer the question
In order to leave comments, you need to log in
Starting counters of digits when scrolling to them, how to do it?
There is a function that runs a digit counter:
$('.counter').each(function() {
$(this).prop('Counter', $(this).data('from')).animate({
Counter: $(this).text()
}, {
duration: $(this).data('duration'),
easing: 'swing',
step: function(now) {
$(this).text(Math.ceil(now))
}
})
});
Answer the question
In order to leave comments, you need to log in
https://webkab.ru/dejstvie-pri-poyavlenii-elementa... - I think it will help
Are you seriously? Today I already answered this question and gave the code How to run a js script at a specific place?
I 'll duplicate it again:
Put the code in a function and call it on the scroll event when it reaches the element you need:
function start_count() {
$('.count').each(function () {
$(this).prop('Counter',0).animate({
Counter: $(this).text()
}, {
duration: 5555,
easing: 'swing',
step: function (now) {
$(this).text(Math.ceil(now));
}
});
});
}
$(function() {
var oTop = $('.count').offset().top - window.innerHeight;
$(window).scroll(function(){
var pTop = $('body').scrollTop();
if( pTop > oTop ){
start_count();
}
});
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question