Last active
May 28, 2018 21:52
-
-
Save michaelbourne/d18b6d6408b3d0c9c24530f568a95e50 to your computer and use it in GitHub Desktop.
Override deafult scroll handling for anchor links, set offset for sticky header.
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
(function($) { | |
$('a[href^="#"]:not(a[href="#"])').unbind('touchend click').on('touchend click', function(e) { | |
var target = $(this.hash); | |
if (target.length) { | |
e.preventDefault(); | |
e.stopImmediatePropagation(); | |
var headerHeight = 50; // put your offset here in px | |
$('html,body').animate({ scrollTop: target.offset().top - headerHeight }, 400); | |
} | |
}); | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment