Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save kier0/c4fa53d7970d8d9f0120 to your computer and use it in GitHub Desktop.

Select an option

Save kier0/c4fa53d7970d8d9f0120 to your computer and use it in GitHub Desktop.
Sticky elements that stop at a certain distance from the bottom. Good for sticky items that should sit on top of the footer when it is in view.
jQuery(document).on("scroll",function(){
if(jQuery(window).scrollTop() + $(window).height() > $(document).height() - 60){
jQuery("div.sticky").addClass("stuck");
} else{
jQuery("div.sticky").removeClass("stuck");
}
});
.sticky.stuck {
position:fixed!important;
bottom:60px!important;
}
footer {
height:60px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment