fillika-smooth-scroll
Version:
Smooth scroll on Vanilla JS
1 lines • 1.6 kB
JavaScript
!function(){"use strict";var t={945:function(t,n,e){e.r(n);var o={linear:function(t,n,e){return n*t/e},easeOutQuad:function(t,n,e){return-n*(t/=e)*(t-2)},easeInQuad:function(t,n,e){return n*(t/=e)*t},easeInOutQuad:function(t,n,e){return(t/=e/2)<1?n/2*t*t:-n/2*(--t*(t-2)-1)},easeInCubic:function(t,n,e){return n*(t/=e)*t*t}},r={duration:350,animationName:"linear",offsetY:0};function i(t){void 0===t&&(t=r);var n=t,e=n.duration,i=void 0===e?r.duration:e,u=n.target,a=n.animationName,f=void 0===a?r.animationName:a,c=n.offsetY,s=void 0===c?r.offsetY:c;if(void 0!==t.target)if(u instanceof HTMLElement){var l=u.getBoundingClientRect().top,d=window.pageYOffset,m=l+d-s,v=d>m?"toTop":"toBottom",p="toTop"===v?d-m:m-d,g=null;requestAnimationFrame((function t(n){null===g&&(g=n);var e=n-g,r=function(t,n,e,r){var i=(0,o[f])(t,e,r),u="toTop"===v?n-i:i+n;switch(v){case"toTop":return u>m?u:m;case"toBottom":return u>m?m:u;default:return u}}(e,d,p,i);window.scrollTo(0,r),e<i&&requestAnimationFrame(t)}))}else console.error("target must be instanceof HTMLElement");else console.error("Требуется передать свойство target в объект config")}window.smoothScroll=i},250:function(t,n,e){e.r(n)},626:function(t,n,e){e.r(n)},564:function(t,n,e){e(945),e(452),e(250),e(626)},452:function(){}},n={};function e(o){if(n[o])return n[o].exports;var r=n[o]={exports:{}};return t[o](r,r.exports,e),r.exports}e.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},e(564)}();