Last active
May 3, 2017 10:01
-
-
Save Takaya213/5500804 to your computer and use it in GitHub Desktop.
Show and hide a scroll to top of page button, depending on where you are on the page.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(window).scroll(function() { | |
if ($(this).scrollTop()) { | |
$('#toTop:hidden').stop(true, true).fadeIn(); | |
} else { | |
$('#toTop').stop(true, true).fadeOut(); | |
} | |
}); | |
$(document).ready(function(){ | |
$('#toTop').fadeOut(); | |
$('#toTop').click(function(){ | |
$('html, body').animate({ | |
scrollTop: $( $.attr(this, 'href') ).offset().top | |
}, 500); | |
return false; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment