Skip to content

Instantly share code, notes, and snippets.

@acbrent25
Created July 21, 2018 15:51
Show Gist options
  • Save acbrent25/d1b18eb3b0d1cb7feef65fab8a43ccd1 to your computer and use it in GitHub Desktop.
Save acbrent25/d1b18eb3b0d1cb7feef65fab8a43ccd1 to your computer and use it in GitHub Desktop.
Website Scroll to Top Button
#scrollTopBtn {
display: none;
position: fixed;
bottom: 0px;
right: 10px;
z-index: 99;
border: none;
outline: none;
color: #303030;
cursor: pointer;
border-radius: 10px;
font-size: 50px;
opacity: .5;
background: none;
}
<button id="scrollTopBtn" title="Go to top"></button>
jQuery(document).ready(function($) {
var scrollBtn = $('#scrollTopBtn');
//Check to see if the window is top if not then display button
$(window).scroll(function(){
if ($(this).scrollTop() > 100) {
$(scrollBtn).fadeIn();
} else {
$(scrollBtn).fadeOut();
}
});
//Click event to scroll to top
$(scrollBtn).click(function(){
$('html, body').animate({scrollTop : 0},800);
return false;
});
}); // Document ready
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment