Last active
August 28, 2016 10:26
-
-
Save adamgavlak/a6cf9c5f7077dc3f4c27e67de1de9ee6 to your computer and use it in GitHub Desktop.
Smooth scrolling to anchor with offset for navigation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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