Last active
December 30, 2020 22:33
-
-
Save kabbo508/1b210dad98eda57c6c328712ced56dbd to your computer and use it in GitHub Desktop.
offsetting an html anchor to adjust for fixed header (*** WORKED - PROVED***)
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($, 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