Skip to content

Instantly share code, notes, and snippets.

@rdallaire
Created May 15, 2013 21:27
Show Gist options
  • Select an option

  • Save rdallaire/5587538 to your computer and use it in GitHub Desktop.

Select an option

Save rdallaire/5587538 to your computer and use it in GitHub Desktop.
Back to top with twitter bootstrap markup
a.backtotop{
position: fixed;
bottom: -4px;
padding-bottom: 16px;
right: 20px;
width: 50px;
}
#top i{
margin: 3px 0 0 5px ;
}
<a href="javascript:void(0)" class="backtotop btn btn-inverse" id="top">Back to Top <i class="icon-arrow-up icon-white"></i></a>
$(window).scroll(function() {// when the page is scrolled run this
if ($(this).scrollTop() != 0) {// if you're NOT at the top
$('#top').fadeIn("fast");
// fade in
} else {// else
$('#top').fadeOut("fast");
// fade out
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment