Skip to content

Instantly share code, notes, and snippets.

@fakiolinho
Created April 21, 2013 20:57
Show Gist options
  • Save fakiolinho/5431051 to your computer and use it in GitHub Desktop.
Save fakiolinho/5431051 to your computer and use it in GitHub Desktop.
jQuery-HTML-CSS: Scroll to Top
/* jQuery Scroll to Top */
function scrollTop() {
$(window).scroll(function() {
$(window).scrollTop() > 50 ? $('#top').fadeIn('slow') : $('#top').fadeOut('slow');
});
$('a[href=#top]').click(function() {
$('html, body').animate({scrollTop:0}, 'slow');
return false;
});
}
<!-- HTML Scroll to Top -->
<div id="top"><a href="#top" class="backtop" title="Back to top">Top</a></div>
/* CSS Scroll to Top */
#top {
display: none;
right: 20px;
bottom: 60px;
position: fixed;
margin: 20px;
}
#top a.backtop {
display: block;
font-size: 12px;
line-height: 35px;
text-align: center;
width: 40px;
height: 40px;
background:url(../img/icon_top.png) no-repeat top left;
opacity: 0.4;
text-indent: -9999em;
}
#top a.backtop:hover {
background:url(../img/icon_top.png) no-repeat top left;
opacity: 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment