Created
June 28, 2018 15:35
-
-
Save geeac/c3c00d7564b44669aff8124909eb877e to your computer and use it in GitHub Desktop.
smooth scroll
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
jQuery(window).load(function($){ | |
function scrollToAnchor(hash) { | |
var target = $(hash), headerHeight; | |
if ($("#wpadminbar").length) { | |
headerHeight = $(".site-header").height() + $("#wpadminbar").height() + 5; // Get fixed header height | |
} | |
else headerHeight = $(".site-header").height() + 5; | |
target = target.length ? target : $('[name=' + hash.slice(1) +']'); | |
if (target.length) | |
{ | |
$('html,body').animate({ | |
scrollTop: target.offset().top - headerHeight | |
}, 100); | |
return false; | |
} | |
} | |
if(window.location.hash) { | |
scrollToAnchor(window.location.hash); | |
} | |
$("a[href*=\\#]:not([href=\\#])").click(function() | |
{ | |
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') | |
|| location.hostname == this.hostname) | |
{ | |
scrollToAnchor(this.hash); | |
} | |
}); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment