Skip to content

Instantly share code, notes, and snippets.

@cole007
Created February 27, 2015 14:42
Show Gist options
  • Save cole007/20890f422bcadae12bc3 to your computer and use it in GitHub Desktop.
Save cole007/20890f422bcadae12bc3 to your computer and use it in GitHub Desktop.
Opacity scroll effect
// http://stackoverflow.com/a/8702428
var fadeStart=100, // 100px scroll or less will equiv to 1 opacity
fadeUntil=800, // 200px scroll or more will equiv to 0 opacity
fading = $('.slider-inner-container-fader');
$(window).bind('scroll', function(){
var offset = $(document).scrollTop(),
opacity=0;
if( offset<=fadeStart ){
opacity=1;
} else if ( offset<=fadeUntil ){
opacity=1-offset/fadeUntil;
}
fading.css('opacity',opacity);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment