Last active
June 8, 2023 01:38
-
-
Save unwiredtech/b2dbb12ed1d1e089f0d61f641702632e to your computer and use it in GitHub Desktop.
Scroll to Top with auto hide
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
// hide the topbutton on page load/ready. | |
jQuery('.scrolltop-btn').hide(); | |
//Check to see if the window is top if not then display button | |
jQuery(window).scroll(function(){ | |
if (jQuery(this).scrollTop() > 100) { | |
jQuery('.scrolltop-btn').show().fadeIn(); | |
} else { | |
jQuery('.scrolltop-btn').fadeOut().hide(); | |
} | |
}); | |
//Click event to scroll to top | |
jQuery('.scrolltop-btn').click(function(){ | |
jQuery('html, body').animate({scrollTop : 0},360); | |
return false; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment