1 line
4.0 KiB
JavaScript
1 line
4.0 KiB
JavaScript
|
"use strict";function polyfill(){function o(o,t){this.scrollLeft=o,this.scrollTop=t}function t(o){return.5*(1-Math.cos(Math.PI*o))}function l(o){if(null===o||"object"!=typeof o||void 0===o.behavior||"auto"===o.behavior||"instant"===o.behavior)return!0;if("object"==typeof o&&"smooth"===o.behavior)return!1;throw new TypeError("behavior member of ScrollOptions "+o.behavior+" is not a valid value for enumeration ScrollBehavior.")}function e(o,t){return"Y"===t?o.clientHeight+h<o.scrollHeight:"X"===t?o.clientWidth+h<o.scrollWidth:void 0}function r(o,t){var l=f.getComputedStyle(o,null)["overflow"+t];return"auto"===l||"scroll"===l}function i(o){var t=e(o,"Y")&&r(o,"Y"),l=e(o,"X")&&r(o,"X");return t||l}function c(o){var t;do o=o.parentNode,t=o===p.body;while(t===!1&&i(o)===!1)return t=null,o}function s(o){var l,e,r,i=u(),c=(i-o.startTime)/d;c=c>1?1:c,l=t(c),e=o.startX+(o.x-o.startX)*l,r=o.startY+(o.y-o.startY)*l,o.method.call(o.scrollable,e,r),e===o.x&&r===o.y||f.requestAnimationFrame(s.bind(f,o))}function n(t,l,e){var r,i,c,n,a=u();t===p.body?(r=f,i=f.scrollX||f.pageXOffset,c=f.scrollY||f.pageYOffset,n=v.scroll):(r=t,i=t.scrollLeft,c=t.scrollTop,n=o),s({scrollable:r,method:n,startTime:a,startX:i,startY:c,x:l,y:e})}var f=window,p=document;if(!("scrollBehavior"in p.documentElement.style&&f.__forceSmoothScrollPolyfill__!==!0)){var a=f.HTMLElement||f.Element,d=468,v={scroll:f.scroll||f.scrollTo,scrollBy:f.scrollBy,elementScroll:a.prototype.scroll||o,scrollIntoView:a.prototype.scrollIntoView},u=f.performance&&f.performance.now?f.performance.now.bind(f.performance):Date.now,h=function(o){var t=["MSIE ","Trident/","Edge/"];return new RegExp(t.join("|")).test(o)}(f.navigator.userAgent)?1:0;f.scroll=f.scrollTo=function(){if(void 0!==arguments[0])return l(arguments[0])===!0?void v.scroll.call(f,void 0!==arguments[0].left?arguments[0].left:"object"!=typeof arguments[0]?arguments[0]:f.scrollX||f.pageXOffset,void 0!==arguments[0].top?arguments[0].top:void 0!==arguments[1]?arguments[1]:f.scrollY||f.pageYOffset):void n.call(f,p.body,void 0!==arguments[0].left?~~arguments[0].left:f.scrollX||f.pageXOffset,void 0!==arguments[0].top?~~arguments[0].top:f.scrollY||f.pageYOffset)},f.scrollBy=function(){if(void 0!==arguments[0])return l(arguments[0])?void v.scrollBy.call(f,void 0!==arguments[0].left?arguments[0].left:"object"!=typeof arguments[0]?arguments[0]:0,void 0!==arguments[0].top?arguments[0].top:void 0!==arguments[1]?arguments[1]:0):void n.call(f,p.body,~~arguments[0].left+(f.scrollX||f.pageXOffset),~~arguments[0].top+(f.scrollY||f.pageYOffset))},a.prototype.scroll=a.prototype.scrollTo=function(){if(void 0!==arguments[0]){if(l(arguments[0])===!0){if("number"==typeof arguments[0]&&void 0===arguments[1])throw new SyntaxError("Value could not be converted");return void v.elementScroll.call(this,void 0!==arguments[0].left?~~arguments[0].left:"object"!=typeof arguments[0]?~~arguments[0]:this.scrollLeft,void 0!==arguments[0].top?~~arguments[0].top:void 0!==arguments[1]?~~arguments[1]:this.scrollTop)}var o=arguments[0].left,t=arguments[0].top;n.call(this,this,void 0===o?this.scrollLeft:~~o,void 0===t?this.scrollTop:~~t)}},a.prototype.scrollBy=function(){if(void 0!==arguments[0])return l(arguments[0])===!0?void v.elementScroll.call(this,void 0!==arguments[0].left?~~arguments[0].left+this.scrollLeft:~~arguments[0]+this.scrollLeft,void 0!==arguments[0].top?~~arguments[0].top+this.scrollTop:~~arguments[1]+this.scrollTop):void this.scroll({left:~~arguments[0].left+this.scrollLeft,top:~~arguments[0].top+this.scrollTop,behavior:arguments[0].behavior})},a.prototype.scrollIntoView=function(){if(l(arguments[0])===!0)return void v.scrollIntoView.call(this,void 0===arguments[0]||arguments[0]);var o=c(this),t=o.getBoundingClientRect(),e=this.getBoundingClientRect();o!==p.body?(n.call(this,o,o.scrollLeft+e.left-t.left,o.scrollTop+e.top-t.top),"fixed"!==f.getComputedStyle(o).position&&f.scrollBy({left:t.left,top:t.top,behavior:"smooth"})):f.scrollBy({left:e.left,top:e.top,behavior:"smooth"})}}}"object"==typeof exports&&"undefined"!=typeof module?module.exports={po
|