Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save juliomoreira666/c5a546d7071275118979fe74d95cc607 to your computer and use it in GitHub Desktop.
Save juliomoreira666/c5a546d7071275118979fe74d95cc607 to your computer and use it in GitHub Desktop.
fade out and hide a fixed element when you scroll to the bottom of the page (jQuery)
//requires jQuery
$(window).scroll(function(){
var threshold = 200; // number of pixels before bottom of page that you want to start fading
var op = (($(document).height() - $(window).height()) - $(window).scrollTop()) / threshold;
if( op <= 0 ){
$("#thing-to-hide").hide();
} else {
$("#thing-to-hide").show();
}
$("#thing-to-hide").css("opacity", op );
});
/*
TODO:
Get working on iOS Safari. Does not fade out completely
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment