Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kabbo508/1b210dad98eda57c6c328712ced56dbd to your computer and use it in GitHub Desktop.
Save kabbo508/1b210dad98eda57c6c328712ced56dbd to your computer and use it in GitHub Desktop.
offsetting an html anchor to adjust for fixed header (*** WORKED - PROVED***)
(function($, window) {
var adjustAnchor = function() {
var $anchor = $(':target'),
fixedElementHeight = 120;
if ($anchor.length > 0) {
$('html, body')
.stop()
.animate({
scrollTop: $anchor.offset().top - fixedElementHeight
}, 250);
}
};
$(window).on('hashchange load', function() {
adjustAnchor();
});
})(jQuery, window);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment