Last active
December 14, 2018 09:27
-
-
Save vfontjr/c5c6815da7f79bafd5616b80628a5272 to your computer and use it in GitHub Desktop.
Genesis anchor scroll fixed-header offset
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( $ ) { | |
// 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