Skip to content

Instantly share code, notes, and snippets.

@rowej83
Last active August 29, 2015 14:02
Show Gist options
  • Save rowej83/3ec49f1214ad7f8c1ee9 to your computer and use it in GitHub Desktop.
Save rowej83/3ec49f1214ad7f8c1ee9 to your computer and use it in GitHub Desktop.
Used to create a short cut to the top of the page if the user scrolls down
/*
Used to create a short cut to the top of the page if the user scrolls down. jQuery is needed.
Required:
Create a div with id="go-to-top" with a nested anchor link.
Place scroll_to_top function inside doc ready().
Place a css condition tag for lte IE9 to set #go-to-top to display:none;
*/
function scroll_to_top() {
$(window).scroll(function () {
if ($(this).scrollTop() > 100) {
$('#go-to-top').stop().animate({
bottom: '20px'
}, 500);
}
else {
$('#go-to-top').stop().animate({
bottom: '-100px'
}, 500);
}
});
$('#go-to-top').click(function () {
$('html, body').stop().animate({
scrollTop: 0
}, 1200, function () {
$('#go-to-top').stop().animate({
bottom: '-100px'
}, 500);
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment