I have a fixed header.
i want to change the opacity when i scroll down and restore the opacity when i scroll up (at top of the page)
i write down this simple script:
$(window).scroll(function () {
if(scrollY == 0){
$("#header").animate({
opacity: 1
}, 1000);
}
if(scrollY > 0){
$("#header").animate({
opacity: 0.5
}, 1000);
}
});
actually the header take the opacity when i scroll down but when i scroll up at the top of the page he NEVER going back to opacity:1.
why?
This might be a better way to go. It checks to see if
#headeris animated before animating the opacity to.5.Also, it caches the
#headerin a variable outside of thescrollhandler. Better for performance.