Mobile app version of vmapp.org
Login or Join
Gonzalez347

: CSS3 animation to start only when page is scrolled to the right place I want to show an CSS3 animation with a delay, but it is below the fold of the page, meaning, that animation may start

@Gonzalez347

Posted in: #Animated #Css3 #Html5

I want to show an CSS3 animation with a delay, but it is below the fold of the page, meaning, that animation may start and end before user scrolls to the area where it should perform.

How can I set up to start the animation when a container DIV gets visible for the user when he scrolls down to this DIV?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Gonzalez347

1 Comments

Sorted by latest first Latest Oldest Best

 

@Bryan171

You can use jQuery (or make it plain JS) to add a class when a certain point has been reached.

var classHadBeenAdded = false;
$(document).on('scroll', function(){
if( !classHadBeenAdded && $(document).scrollTop() < foldValue ){
$('#element').addClass('ClassWithAnimation');
classHadBeenAdded = true; // save change so it doesnt double.
}
});


You might want to add a dethrottle to it to prevent the number of calls jamming your browser.



Another method is a variant, make transition-delay something very high, and change that value with JS upon the triggerpoint.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme