Last active
August 12, 2021 21:26
-
-
Save taotiwordpress/94f1163a71a5fff0a34b1e11e6080fa2 to your computer and use it in GitHub Desktop.
[Back to top button]
This file contains hidden or 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
jQuery(window).on('load',function(){ | |
//Click event to scroll to top | |
$('#back-to-top').click(function(){ | |
$('html, body').animate({scrollTop : 0},800); | |
return false; | |
}); | |
}); | |
jQuery(window).scroll(returnTop); | |
function returnTop() { | |
// Show button after 100px | |
var showAfter = 100; | |
if ( $(this).scrollTop() > showAfter ) { | |
$('#back-to-top').fadeIn(); | |
} else { | |
$('#back-to-top').fadeOut(); | |
} | |
} |
This file contains hidden or 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
#back-to-top { | |
position: fixed; | |
bottom: 8px; | |
right: 8px; | |
z-index: 9999; | |
cursor: pointer; | |
text-decoration: none; | |
vertical-align: middle; | |
display: none; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment