Tell me what I was wrong.
I do it here http://landing.romza.ru , but my numbers run in a circle, and do not stop, reaching the maximum value ((

$(window).scroll(function() { $('.p1').each(function(){ var imagePos = $(this).offset().top; var topOfWindow = $(window).scrollTop(); if (imagePos = topOfWindow+600) { $(this).animateNumber({ number: 10 }); } }); }); 

UPD:

This script works correctly, but it starts immediately when the page loads. How to start it when scrolling to the element?

 $('.num').countTo({ from: 0, speed: 100, refreshInterval: 1, formatter: function (value, options) { return value.toFixed(options.decimals); } }); 
  • You in the condition do not compare values, but assign a new value to the imagePos variable! - Ihor Tkachuk
  • But how to fix? - Batyabest
  • Use instead = double equals == . You can read: developer.mozilla.org/ru/docs/Web/JavaScript/Reference/… - Ihor Tkachuk
  • It does not work at all. I noticed that the animation runs not in a circle, but as if several times. That is, I reached 10 and then again from 0 to 10 and so 3-4 times. - Batyabest
  • Chopped up another script - but the problem is different - stated in the UPD to the question. - Batyabest

1 answer 1

Try using

 $(window).scroll(function() { $('.p1').each(function(){ var imagePos = $(this).offset().top; var topOfWindow = $(window).scrollTop(); if (imagePos = topOfWindow+600) { $(this).animateNumber({ number: 10 }); $(this).stop(); } }); 

});

  • Does not work. No animation at all. - Batyabest