Skip to content

Instantly share code, notes, and snippets.

@motorcitymobi
Created January 22, 2013 18:35
Show Gist options
  • Save motorcitymobi/4597091 to your computer and use it in GitHub Desktop.
Save motorcitymobi/4597091 to your computer and use it in GitHub Desktop.
Scroll to Top
JS:
//Scroll to Top
$(function() {
jQuery(window).scroll(function() {
if(jQuery(this).scrollTop() > 150) {
jQuery('.up').fadeIn();
} else {
jQuery('.up').fadeOut();
}
});
});
$('.up').live('click', function() {
$('html, body').animate({scrollTop: '0'}, 200);
});
HTML:
<a href="#wrap" class="up" style="display: block; ">scroll to top</a>
CSS:
a.up {
background: url(http://mcmdemos.com/veracruz/wp-content/themes/veracruz/library/images/totop.png) no-repeat scroll 0 0;
width: 39px;
height: 42px;
position: fixed;
bottom: 0;
right: 0;
text-indent: -9999px;
z-index: 9999;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment