Skip to content

Instantly share code, notes, and snippets.

@xrksudy
Last active December 21, 2015 05:29
Show Gist options
  • Save xrksudy/6257268 to your computer and use it in GitHub Desktop.
Save xrksudy/6257268 to your computer and use it in GitHub Desktop.
Back To Top
var $backtotop = $('#backtotop');
var top = $(window).height() - $backtotop.height() - 200;
function moveBacktotop() {
$backtotop.css({ top: top, right: 0});
}
$backtotop.click(function () {
$('html,body').animate({ scrollTop: 0 });
return false;
});
$(window).scroll(function () {
var windowHeight = $(window).scrollTop();
if (windowHeight > 200) {
$backtotop.fadeIn();
} else {
$backtotop.fadeOut();
}
});
moveBacktotop();
$(window).resize(moveBacktotop);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment