Skip to content

Instantly share code, notes, and snippets.

@vfontjr
Last active December 14, 2018 09:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vfontjr/c5c6815da7f79bafd5616b80628a5272 to your computer and use it in GitHub Desktop.
Save vfontjr/c5c6815da7f79bafd5616b80628a5272 to your computer and use it in GitHub Desktop.
Genesis anchor scroll fixed-header offset
(function( $ ) {
// Make sure JS is enabled.
document.documentElement.className = 'js';
$(document).ready(function() {
$( 'a[href*=#]:not([href=#])' ).click(function() {
if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
var target = $(this.hash), admin_offset, header_height, offset;
target = target.length ? target : $( '[name=' + this.hash.slice(1) + ']' );
admin_offset = $("body").hasClass("admin-bar") ? 32 : 0;
header_height = $('header.site-header').outerHeight();
offset = header_height + admin_offset;
if (target.length) {
$( 'html,body' ).animate({
scrollTop: target.offset().top - offset
}, 1000);
return false;
}
}
});
});
})( jQuery );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment