| 1 |
|
| 2 |
_initWheel: function () { |
| 3 |
utils.addEvent(this.wrapper, 'wheel', this); |
| 4 |
utils.addEvent(this.wrapper, 'mousewheel', this); |
| 5 |
utils.addEvent(this.wrapper, 'DOMMouseScroll', this); |
| 6 |
|
| 7 |
this.on('destroy', function () { |
| 8 |
clearTimeout(this.wheelTimeout); |
| 9 |
this.wheelTimeout = null; |
| 10 |
utils.removeEvent(this.wrapper, 'wheel', this); |
| 11 |
utils.removeEvent(this.wrapper, 'mousewheel', this); |
| 12 |
utils.removeEvent(this.wrapper, 'DOMMouseScroll', this); |
| 13 |
}); |
| 14 |
}, |
| 15 |
|
| 16 |
_wheel: function (e) { |
| 17 |
if ( !this.enabled ) { |
| 18 |
return; |
| 19 |
} |
| 20 |
|
| 21 |
e.preventDefault(); |
| 22 |
|
| 23 |
var wheelDeltaX, wheelDeltaY, |
| 24 |
newX, newY, |
| 25 |
that = this; |
| 26 |
|
| 27 |
if ( this.wheelTimeout === undefined ) { |
| 28 |
that._execEvent('scrollStart'); |
| 29 |
} |
| 30 |
|
| 31 |
|
| 32 |
clearTimeout(this.wheelTimeout); |
| 33 |
this.wheelTimeout = setTimeout(function () { |
| 34 |
if(!that.options.snap) { |
| 35 |
that._execEvent('scrollEnd'); |
| 36 |
} |
| 37 |
that.wheelTimeout = undefined; |
| 38 |
}, 400); |
| 39 |
|
| 40 |
if ( 'deltaX' in e ) { |
| 41 |
if (e.deltaMode === 1) { |
| 42 |
wheelDeltaX = -e.deltaX * this.options.mouseWheelSpeed; |
| 43 |
wheelDeltaY = -e.deltaY * this.options.mouseWheelSpeed; |
| 44 |
} else { |
| 45 |
wheelDeltaX = -e.deltaX; |
| 46 |
wheelDeltaY = -e.deltaY; |
| 47 |
} |
| 48 |
} else if ( 'wheelDeltaX' in e ) { |
| 49 |
wheelDeltaX = e.wheelDeltaX / 120 * this.options.mouseWheelSpeed; |
| 50 |
wheelDeltaY = e.wheelDeltaY / 120 * this.options.mouseWheelSpeed; |
| 51 |
} else if ( 'wheelDelta' in e ) { |
| 52 |
wheelDeltaX = wheelDeltaY = e.wheelDelta / 120 * this.options.mouseWheelSpeed; |
| 53 |
} else if ( 'detail' in e ) { |
| 54 |
wheelDeltaX = wheelDeltaY = -e.detail / 3 * this.options.mouseWheelSpeed; |
| 55 |
} else { |
| 56 |
return; |
| 57 |
} |
| 58 |
|
| 59 |
wheelDeltaX *= this.options.invertWheelDirection; |
| 60 |
wheelDeltaY *= this.options.invertWheelDirection; |
| 61 |
|
| 62 |
if ( !this.hasVerticalScroll ) { |
| 63 |
wheelDeltaX = wheelDeltaY; |
| 64 |
wheelDeltaY = 0; |
| 65 |
} |
| 66 |
|
| 67 |
if ( this.options.snap ) { |
| 68 |
newX = this.currentPage.pageX; |
| 69 |
newY = this.currentPage.pageY; |
| 70 |
|
| 71 |
if ( wheelDeltaX > 0 ) { |
| 72 |
newX--; |
| 73 |
} else if ( wheelDeltaX < 0 ) { |
| 74 |
newX++; |
| 75 |
} |
| 76 |
|
| 77 |
if ( wheelDeltaY > 0 ) { |
| 78 |
newY--; |
| 79 |
} else if ( wheelDeltaY < 0 ) { |
| 80 |
newY++; |
| 81 |
} |
| 82 |
|
| 83 |
this.goToPage(newX, newY); |
| 84 |
|
| 85 |
return; |
| 86 |
} |
| 87 |
|
| 88 |
newX = this.x + Math.round(this.hasHorizontalScroll ? wheelDeltaX : 0); |
| 89 |
newY = this.y + Math.round(this.hasVerticalScroll ? wheelDeltaY : 0); |
| 90 |
|
| 91 |
this.directionX = wheelDeltaX > 0 ? -1 : wheelDeltaX < 0 ? 1 : 0; |
| 92 |
this.directionY = wheelDeltaY > 0 ? -1 : wheelDeltaY < 0 ? 1 : 0; |
| 93 |
|
| 94 |
if ( newX > 0 ) { |
| 95 |
newX = 0; |
| 96 |
} else if ( newX < this.maxScrollX ) { |
| 97 |
newX = this.maxScrollX; |
| 98 |
} |
| 99 |
|
| 100 |
if ( newY > 0 ) { |
| 101 |
newY = 0; |
| 102 |
} else if ( newY < this.maxScrollY ) { |
| 103 |
newY = this.maxScrollY; |
| 104 |
} |
| 105 |
|
| 106 |
this.scrollTo(newX, newY, 0); |
| 107 |
|
| 108 |
|
| 109 |
}, |