Skip to content

Instantly share code, notes, and snippets.

@stephenscaff
Last active December 22, 2015 23:49
Show Gist options
  • Save stephenscaff/6549826 to your computer and use it in GitHub Desktop.
Save stephenscaff/6549826 to your computer and use it in GitHub Desktop.
Got a scroll-based site with more than one page, and some page anchor nav links? Nice. But, when clicking a page anchor link from another page, let's load the new page first, slow our damn rolls, then scroll down to the bad boy all sexy like. Throw in a bit of offset for a fixed nav too. Don't forget them easing equations son. They make life wor…
//Scroll to anchor on new page load
$(document).ready(function() {
//This a page anchor link?
if (window.location.hash) {
//Then, slow your roll son, load then scroll
setTimeout(function() {
$('html, body').scrollTop(0).show();
$('html, body').animate({
//how about a touch of offset, cause I'm rockin' a fixed nav
scrollTop: $(window.location.hash).offset().top-50
}, 2000, 'easeInOutQuad')
}, 2);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment