Skip to content

Instantly share code, notes, and snippets.

@oliverbenns
Last active December 23, 2015 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oliverbenns/6660703 to your computer and use it in GitHub Desktop.
Save oliverbenns/6660703 to your computer and use it in GitHub Desktop.
Simple 'To Top' button script if browser goes below the fold.
$(window).scroll(function() {
var window_height = $(window).height();
if ( $(window).scrollTop() > window_height ) {
$('.to-top').addClass('show');
} else {
$('.to-top').removeClass('show');
}
});
<div class="to-top">To Top</div>
.to-top {
display: none;
position: fixed;
/* style/position where you like */
bottom: 40px;
left: 40px;
}
.show {
display: block;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment