Created
September 11, 2016 06:38
-
-
Save alyssachk/5c337d0e5f89477851583c2ccfa89e30 to your computer and use it in GitHub Desktop.
Back to Top Button jQuery
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
<a href="#" class="back-to-top">回到頁首</a> | |
<script> | |
jQuery(document).ready(function() { | |
var offset = 220; | |
var duration = 500; | |
jQuery(window).scroll(function() { | |
if (jQuery(this).scrollTop() > offset) { | |
jQuery('.back-to-top').fadeIn(duration); | |
} else { | |
jQuery('.back-to-top').fadeOut(duration); | |
} | |
}); | |
jQuery('.back-to-top').click(function(event) { | |
event.preventDefault(); | |
jQuery('html, body').animate({scrollTop: 0}, duration); | |
return false; | |
}) | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment