Timur Timur - 3 months ago 20
jQuery Question

On scroll function replay animation on each scroll

I am trying to make circle progress bar to loading when user scroll down to that section.

When user reach certain point it triggers function and progress bar animates, but if you scroll up and down it will restart function, how can it be fix?

$(window).scroll(function() {
var wScroll = $(this).scrollTop();
if (wScroll > $('#skills').offset().top - ($(window).height() / 1.9)) {
//PROGRESS BAR CODE GOES HERE
}


DEMO

Answer

Just check if animation started and don't restart if it is.

if (window.playing) return;
window.playing = true;

UPDATED PEN