What is the best way if I want to animate an element on scroll? because I noticed that it lags a little bit while scrolling. should I add the class like this?
$(window).scroll(function() {
if($(this).scrollTop() > 500) {
$(".element").addClass("animateElement");
}
}
or make a flag like this one.
animateFlag = true;
$(window).scroll(function() {
if($(this).scrollTop() > 500) {
if(animateFlag) {
$(".element").addClass("animateElement");
animateFlag = false;
}
}
}