Skip to content

Instantly share code, notes, and snippets.

@vishnusomanus
Created November 7, 2016 08:45
Show Gist options
  • Save vishnusomanus/f952fae859fb317599362fdc94afbfe7 to your computer and use it in GitHub Desktop.
Save vishnusomanus/f952fae859fb317599362fdc94afbfe7 to your computer and use it in GitHub Desktop.
<a href="#" class="scrollToTop" style=" width: 77px; padding: 5px; text-align: center; background-color: #c42e2f; font-weight: bold; color: #ffffff; text-decoration: none; position: fixed; bottom: 60px; right: 40px; display: none; border-radius: 50px;"><i class="fa fa-chevron-up" aria-hidden="true"></i></a>
<script type="text/javascript">
jQuery(document).ready(function(){
//Check to see if the window is top if not then display button
jQuery(window).scroll(function(){
if (jQuery(this).scrollTop() > 100) {
jQuery('.scrollToTop').fadeIn();
} else {
jQuery('.scrollToTop').fadeOut();
}
});
//Click event to scroll to top
jQuery('.scrollToTop').click(function(){
jQuery('html, body').animate({scrollTop : 0},800);
return false;
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment