apamphilon

Fade / Animate Element On Scroll

var fadeStart=0, // 100px scroll or less will equiv to 1 opacity
fadeUntil=500, // 200px scroll or more will equiv to 0 opacity
fading = $('.scroll-down');

$(window).bind('scroll', function(){
    var offset = $(document).scrollTop(),opacity=0;
    if( offset<=fadeStart ){
        opacity=1;
    }else if( offset<=fadeUntil ){
        fading.show();
        opacity=1-offset/fadeUntil;
    }else if( offset > fadeUntil ){
        fading.hide();
    }
    fading.css('opacity',opacity);
});

Credit


Comments: