Created
March 6, 2017 12:28
-
-
Save jpescada/9dabc09473407e78880ab494de7b29cd to your computer and use it in GitHub Desktop.
Smooth scrolling JS
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
$(function() { | |
'use strict'; | |
// Define only easing functions required | |
jQuery.extend( jQuery.easing, | |
{ | |
easeOutQuart: function (x, t, b, c, d) { | |
return -c * ((t=t/d-1)*t*t*t - 1) + b; | |
} | |
}); | |
// Smooth scroll into anchors | |
// source: https://css-tricks.com/snippets/jquery/smooth-scrolling/ | |
$('a[href*="#"]:not([href="#"])').click(function() { | |
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) { | |
$('html, body').animate({ | |
scrollTop: target.offset().top | |
}, 1000, 'easeOutQuart'); | |
return false; | |
} | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment