Skip to content

Instantly share code, notes, and snippets.

@adamgavlak
Last active August 28, 2016 10:26
Show Gist options
  • Save adamgavlak/a6cf9c5f7077dc3f4c27e67de1de9ee6 to your computer and use it in GitHub Desktop.
Save adamgavlak/a6cf9c5f7077dc3f4c27e67de1de9ee6 to your computer and use it in GitHub Desktop.
Smooth scrolling to anchor with offset for navigation
var offset = 60;
$("a[href*=#]:not([href=#])").click(function() {
if (location.pathname.replace(/^\//, "") == this.pathname.replace(/^\//, "") || location.hostname == this.hostname) {
var t = $(this.hash);
if (t = t.length ? t : $("[name=" + this.hash.slice(1) + "]"), t.length)
return $("html,body").animate( {scrollTop: t.offset().top - offset}, 1e3), !1
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment