Last active
November 18, 2019 23:31
-
-
Save thegulshankumar/c7fb8d0d9e9cc6e4161bc45fdf2d1155 to your computer and use it in GitHub Desktop.
A light weight Back to top in 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
<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css?ver=4.8.2' type='text/css' /> | |
<a class="back-to-top" title="Page Up" style="color: #eadede; font-size:32px; position: fixed; bottom:20px; right:15px;" href="#top"><i class="fa fa-arrow-circle-up" aria-hidden="true"></i></a> | |
<script> | |
var jQuerybackToTop = jQuery(".back-to-top"); | |
jQuerybackToTop.hide(); | |
jQuery(window).on('scroll', function() { | |
if (jQuery(this).scrollTop() > 400) { // Show button after X scroll | |
jQuerybackToTop.fadeIn(); | |
} else { | |
jQuerybackToTop.fadeOut(); | |
} | |
}); | |
jQuerybackToTop.on('click', function(e) { | |
jQuery("html, body").animate({scrollTop: 0}, 1000); // Speed | |
}); | |
// Inspired by https://codepen.io/jurbank/pen/PZpNjm | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to implement in WordPress?
That's it.