Skip to content

Instantly share code, notes, and snippets.

@krishna19
Forked from wpscholar/smooth-scroll.jquery.js
Created October 3, 2016 10:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krishna19/ee5413b49ca36e5054fcfd8bc0a83721 to your computer and use it in GitHub Desktop.
Save krishna19/ee5413b49ca36e5054fcfd8bc0a83721 to your computer and use it in GitHub Desktop.
Implement smooth scroll for all internal page links.
// 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