Last active
September 18, 2021 21:49
-
-
Save billerickson/804efbdee63a0a113d12 to your computer and use it in GitHub Desktop.
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
// Smooth scrolling anchor links | |
function ea_scroll( hash ) { | |
var target = $( hash ); | |
target = target.length ? target : $('[name=' + this.hash.slice(1) +']'); | |
if (target.length) { | |
var top_offset = 0; | |
if ( $('.site-header').css('position') == 'fixed' ) { | |
top_offset = $('.site-header').height(); | |
} | |
if( $('body').hasClass('admin-bar') ) { | |
top_offset = top_offset + $('#wpadminbar').height(); | |
} | |
$('html,body').animate({ | |
scrollTop: target.offset().top - top_offset | |
}, 1000); | |
return false; | |
} | |
} | |
// -- Smooth scroll on pageload | |
if( window.location.hash ) { | |
ea_scroll( window.location.hash ); | |
} | |
// -- Smooth scroll on click | |
$('a[href*="#"]:not([href="#"]):not(.no-scroll)').click(function() { | |
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') || location.hostname == this.hostname) { | |
ea_scroll( this.hash ); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment