Created
February 2, 2017 18:20
-
-
Save alyssachanspace/a66843b672db7ec3ced7fd69f8a746cd to your computer and use it in GitHub Desktop.
jQuery script of Back to Top button
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