Question

I want to animate my header if the page is scrolled down (lets say 300px).

How can i realize this in jquery?

Something like :

if (scrolled > 300px) {
$('.mydiv').slideUp();
}
else (scrolled < 300px) {
$('.mydiv').slideDown();
 }

thank you!

Was it helpful?

Solution

Try this:

$(document).scroll(function() {
    if( $(this).scrollTop() > 300 ) {
        $('.mydiv').slideUp();
    } else {
        $('.mydiv').slideDown();
    }
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top