-
Notifications
You must be signed in to change notification settings - Fork 0
/
smoothscroll.min.js
1 lines (1 loc) · 995 Bytes
/
smoothscroll.min.js
1
window.smoothScroll=function(){if(void 0!==document.querySelectorAll&&void 0!==window.pageYOffset&&void 0!==history.pushState){var e=function(e){return"HTML"===e.nodeName?-window.pageYOffset:e.getBoundingClientRect().top+window.pageYOffset},n=function(e){return.5>e?4*e*e*e:(e-1)*(2*e-2)*(2*e-2)+1},t=function(e,t,o,i){return o>i?t:e+(t-e)*n(o/i)},o=function(n,o,i){o=o||500;var r=window.pageYOffset;if("number"==typeof n)var u=parseInt(n);else var u=e(n);var a=Date.now(),d=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||function(e){window.setTimeout(e,15)},f=function(){var e=Date.now()-a;window.scroll(0,t(r,u,e,o)),e>o?"function"==typeof i&&i(n):d(f)};f()},i=function(e){e.preventDefault(),o(document.getElementById(this.hash.substring(1)),500,function(e){})};return document.addEventListener("DOMContentLoaded",function(){for(var e,n=document.querySelectorAll('a[href^="#"]'),t=n.length;e=n[--t];)e.addEventListener("click",i,!1)}),o}}();