Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dylanjhunt/b6078c4b756e033d667830ad3176a947 to your computer and use it in GitHub Desktop.
Save dylanjhunt/b6078c4b756e033d667830ad3176a947 to your computer and use it in GitHub Desktop.
Smooth Scrolling Javascript for Shopify
$('a[href*="#"]')
.not('[href="#"]')
.not('[href="#0"]')
.click(function(event) {
if (
location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '')
&&
location.hostname == this.hostname
) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
if (target.length) {
event.preventDefault();
$('html, body').animate({
scrollTop: target.offset().top
}, 1000, function() {
var $target = $(target);
$target.focus();
if ($target.is(":focus")) {
return false;
} else {
$target.attr('tabindex','-1');
$target.focus();
};
});
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment