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
!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(Math.round(e.y)+t.x,d),this.scroll.trigger(this.scroll.eventTypes.mousewheelMove,{x:n,y:s})||(l=this.getEaseTime(),n===this.scroll.x&&s===this.scroll.y||this.scroll.scrollTo(n,s,l)),c&&(this.wheelMoveTimer=window.setTimeout(function(){a.wheelMoveTimer=0},c)))},d.prototype.wheelEndDetector=function(e){var t=this;window.clearTimeout(this.wheelEndTimer),this.wheelEndTimer=window.setTimeout(function(){t.wheelStart=!1,window.clearTimeout(t.wheelMoveTimer),t.wheelMoveTimer=0,t.scroll.trigger(t.scroll.eventTypes.mousewheelEnd,e)},this.mouseWheelOpt.discreteTime)},d.prototype.getWheelDelta=function(e){var t=this.mouseWheelOpt,o=t.speed,r=0,i=0,n=t.invert?-1:1;switch(!0){case"deltaX"in e:i=1===e.deltaMode?(r=-e.deltaX*o,-e.deltaY*o):(r=-e.deltaX,-e.deltaY);break;case"wheelDeltaX"in e:r=e.wheelDeltaX/120*o,i=e.wheelDeltaY/120*o;break;case"wheelDelta"in e:r=i=e.wheelDelta/120*o;break;case"detail"in e:r=i=-e.detail/3*o}return r*=n,i*=n,this.scroll.hasVerticalScroll||(r=i,i=0),this.scroll.hasHorizontalScroll||(r=0),{x:r,y:i,directionX:0<r?-1:r<0?1:0,directionY:0<i?-1:i<0?1:0}},d.prototype.beforeHandler=function(e){var t=this.scroll.options,o=t.preventDefault,r=t.stopPropagation,i=t.preventDefaultException;o&&!function(e,t){for(var o in t)if(t[o].test(e[o]))return 1}(e.target,i)&&e.preventDefault(),r&&e.stopPropagation()},d.prototype.getEaseTime=function(){var e=this.mouseWheelOpt.easeTime;return e<100&&console.error("[BScroll warn]: easeTime should be greater than 100.If mouseWheel easeTime is too small,scrollEnd will be triggered many times."),Math.max(e,100)},d.prototype.destroy=function(){this.eventRegister.destroy(),window.clearTimeout(this.wheelEndTimer),window.clearTimeout(this.wheelMoveTimer),this.hooksFn.forEach(function(e){var t=e[0],o=e[1],r=e[2];t.off(o,r)})},d.pluginName="mouseWheel",d.applyOrder="pre",d});
|