Faced a problem so that when scrolling down on the page, elements appear, after they have already appeared, the dosihpor script works, with each scrolling it continues to add the class active how to stop it. js:

$(window).scroll(function() { $(".advantage-options").each(function() { var pos = $(this).offset().top; var winTop = $(window).scrollTop(); if (pos < winTop + 780) { var i = 0; var interval = setInterval(function() { var cont = document.getElementsByClassName("adv-item"); if (i < cont.length) { cont[i].className += " active"; i++; } else { clearInterval(interval); } }, 120); } }); }); 

    1 answer 1

    Perform a check:

     if(cont[i].className.indexOf("active")==-1){ cont[i].className += " active"; } 

    Or use jQuery, since you are still using:

     $(".adv-item").addClass("active"); 

    The same version with jQuery, but with the element number:

     $(".adv-item").eq(i).addClass("active");