Skip to content

Instantly share code, notes, and snippets.

@BryanBarrera
Created September 25, 2015 02:06
Show Gist options
  • Save BryanBarrera/9b6d9d86c460595c59f7 to your computer and use it in GitHub Desktop.
Save BryanBarrera/9b6d9d86c460595c59f7 to your computer and use it in GitHub Desktop.
Scroll to the top of the page after certain amount of pixels
// Scroll To Top
jQuery("a[href='#top']").click(function () {
jQuery("html, body").animate({
scrollTop: 0
}, "slow");
return false;
});
// hide button
jQuery('.elementBtn').hide();
// after 200 pixels show if, else hide/fadeout
jQuery(window).scroll(function () {
if (jQuery(this).scrollTop() > 200) {
jQuery('.elementBtn').fadeIn();
} else {
jQuery('.elementBtn').fadeOut();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment