Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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