Skip to content

Instantly share code, notes, and snippets.

@adalenv
Created July 19, 2017 12:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adalenv/309261f7d185c3b0745e5fc27d9bcdd4 to your computer and use it in GitHub Desktop.
Save adalenv/309261f7d185c3b0745e5fc27d9bcdd4 to your computer and use it in GitHub Desktop.
$(document).ready(function() {
var offset=250, // At what pixels show Back to Top Button
scrollDuration=300; // Duration of scrolling to top
$(window).scroll(function() {
if ($(this).scrollTop() > offset) {
$('.top').fadeIn(500); // Time(in Milliseconds) of appearing of the Button when scrolling down.
} else {
$('.top').fadeOut(500); // Time(in Milliseconds) of disappearing of Button when scrolling up.
}
});
// Smooth animation when scrolling
$('.top').click(function(event) {
event.preventDefault();
$('html, body').animate({
scrollTop: 0}, scrollDuration);
})
});
/////////////////////// adalenv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment