You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2 lines
5.8 KiB
2 lines
5.8 KiB
4 years ago
|
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).MouseWheel=t()}(this,function(){"use strict";var r="undefined"!=typeof window,o=r&&navigator.userAgent.toLowerCase(),i=(o&&/wechatdevtools/.test(o),o&&o.indexOf("android"),function(){if("string"!=typeof o)return;var e=/os (\d\d?_\d(_\d)?)/.exec(o);if(!e)return;var t=e[1].split("_").map(function(e){return parseInt(e,10)});13<=t[0]&&t[1]}(),r&&document.createElement("div").style),t=function(){if(!r)return!1;for(var e=0,t=[{key:"standard",value:"transform"},{key:"webkit",value:"webkitTransform"},{key:"Moz",value:"MozTransform"},{key:"O",value:"OTransform"},{key:"ms",value:"msTransform"}];e<t.length;e++){var o=t[e];if(void 0!==i[o.value])return o.key}return!1}();function e(e){return!1===t?e:"standard"===t?"transitionEnd"===e?"transitionend":e:t+e.charAt(0).toUpperCase()+e.substr(1)}function n(e,t,o,r){e.addEventListener(t,o,{passive:!1,capture:!!r})}function s(e,t,o,r){e.removeEventListener(t,o,{capture:!!r})}t&&"standard"!==t&&t.toLowerCase();var l=e("transform"),a=e("transition");r&&e("perspective")in i,e("transitionTimingFunction"),e("transitionDuration"),e("transitionDelay"),e("transformOrigin"),e("transitionEnd"),e("transitionProperty");var h=(c.prototype.destroy=function(){this.removeDOMEvents(),this.events=[]},c.prototype.addDOMEvents=function(){this.handleDOMEvents(n)},c.prototype.removeDOMEvents=function(){this.handleDOMEvents(s)},c.prototype.handleDOMEvents=function(t){var o=this,r=this.wrapper;this.events.forEach(function(e){t(r,e.name,o,!!e.capture)})},c.prototype.handleEvent=function(t){var o=t.type;this.events.some(function(e){return e.name===o&&(e.handler(t),!0)})},c);function c(e,t){this.wrapper=e,this.events=t,this.addDOMEvents()}function d(e){this.scroll=e,this.wheelEndTimer=0,this.wheelMoveTimer=0,this.wheelStart=!1,this.init()}return d.prototype.init=function(){this.handleBScroll(),this.handleOptions(),this.handleHooks(),this.registerEvent()},d.prototype.handleBScroll=function(){this.scroll.registerType(["alterOptions","mousewheelStart","mousewheelMove","mousewheelEnd"])},d.prototype.handleOptions=function(){var e=!0===this.scroll.options.mouseWheel?{}:this.scroll.options.mouseWheel;this.mouseWheelOpt=function(e,t){for(var o in t)e[o]=t[o];return e}({speed:20,invert:!1,easeTime:300,discreteTime:400,throttleTime:0,dampingFactor:.1},e)},d.prototype.handleHooks=function(){this.hooksFn=[],this.registerHooks(this.scroll.hooks,"destroy",this.destroy)},d.prototype.registerEvent=function(){this.eventRegister=new h(this.scroll.scroller.wrapper,[{name:"wheel",handler:this.wheelHandler.bind(this)},{name:"mousewheel",handler:this.wheelHandler.bind(this)},{name:"DOMMouseScroll",handler:this.wheelHandler.bind(this)}])},d.prototype.registerHooks=function(e,t,o){e.on(t,o,this),this.hooksFn.push([e,t,o])},d.prototype.wheelHandler=function(e){var t;this.scroll.enabled&&(this.beforeHandler(e),this.wheelStart||(this.wheelStartHandler(e),this.wheelStart=!0),t=this.getWheelDelta(e),this.wheelMoveHandler(t),this.wheelEndDetector(t))},d.prototype.wheelStartHandler=function(e){this.cleanCache();var t=this.scroll.scroller,o=t.scrollBehaviorX,r=t.scrollBehaviorY;o.setMovingDirection(0),r.setMovingDirection(0),o.setDirection(0),r.setDirection(0),this.scroll.trigger(this.scroll.eventTypes.alterOptions,this.mouseWheelOpt),this.scroll.trigger(this.scroll.eventTypes.mousewheelStart)},d.prototype.cleanCache=function(){this.deltaCache=[]},d.prototype.wheelMoveHandler=function(e){var t,o,r,i,n,s,l,a=this,h=this.mouseWheelOpt,c=h.throttleTime,d=h.dampingFactor;c&&this.wheelMoveTimer?this.deltaCache.push(e):(t=this.deltaCache.reduce(function(e,t){return{x:e.x+t.x,y:e.y+t.y}},{x:0,y:0}),this.cleanCache(),r=(o=this.scroll.scroller).scrollBehaviorX,i=o.scrollBehaviorY,r.setMovingDirection(-e.directionX),i.setMovingDirection(-e.directionY),r.setDirection(e.x),i.setDirection(e.y),n=r.performDampingAlgorithm(Math.round(e.x)+t.x,d),s=i.performDampingAlgorithm(Ma
|