Created
March 15, 2016 15:50
-
-
Save wpscholar/c6ea30e1aaf49070c2a9 to your computer and use it in GitHub Desktop.
Implement smooth scroll for all internal page links.
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 Scroll | |
$('a[href*="#"]:not([href="#"])').click(function () { | |
var target = $(this.hash); | |
if (target.length) { | |
var isInternalLink = new RegExp('/' + window.location.host + '/'); | |
if (isInternalLink.test(this.href)) { | |
$('html, body').animate({scrollTop: target.offset().top}, 1000); | |
return false; | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment