This may be the best way to go. It checks to see if #headeranimations are animated before animating to .5.
In addition, it caches #headerin a variable outside the handler scroll. Better for performance.
var $header = $('#header');
$(window).scroll(function () {
if(scrollY <= 0){
$header.animate({
opacity: 1
}, 1000);
}
if(scrollY > 0 && $header.is(':not(:animated)')){
$header.animate({
opacity: .5
}, 1000);
}
});
source
share