Elffuss BraidHub

kikocis/iscroll public

f894cb244bec · 1.5 KiBRawPermalink
1
2 _initWheel: function () {
3 utils.addEvent(this.wrapper, 'mousewheel', this);
4 utils.addEvent(this.wrapper, 'DOMMouseScroll', this);
5
6 this.on('destroy', function () {
7 utils.removeEvent(this.wrapper, 'mousewheel', this);
8 utils.removeEvent(this.wrapper, 'DOMMouseScroll', this);
9 });
10 },
11
12 _wheel: function (e) {
13 var wheelDeltaX, wheelDeltaY,
14 newX, newY,
15 that = this;
16
17 // Execute the scrollEnd event after 400ms the wheel stopped scrolling
18 clearTimeout(this.wheelTimeout);
19 this.wheelTimeout = setTimeout(function () {
20 that._execEvent('scrollEnd');
21 }, 400);
22
23 e.preventDefault();
24
25 if ( 'wheelDeltaX' in e ) {
26 wheelDeltaX = e.wheelDeltaX / 120;
27 wheelDeltaY = e.wheelDeltaY / 120;
28 } else if ( 'wheelDelta' in e ) {
29 wheelDeltaX = wheelDeltaY = e.wheelDelta / 120;
30 } else if ( 'detail' in e ) {
31 wheelDeltaX = wheelDeltaY = -e.detail / 3;
32 } else {
33 return;
34 }
35
36 wheelDeltaX *= this.options.mouseWheelSpeed;
37 wheelDeltaY *= this.options.mouseWheelSpeed;
38
39 if ( !this.hasVerticalScroll ) {
40 wheelDeltaX = wheelDeltaY;
41 }
42
43 newX = this.x + (this.hasHorizontalScroll ? wheelDeltaX * this.options.invertWheelDirection : 0);
44 newY = this.y + (this.hasVerticalScroll ? wheelDeltaY * this.options.invertWheelDirection : 0);
45
46 if ( newX > 0 ) {
47 newX = 0;
48 } else if ( newX < this.maxScrollX ) {
49 newX = this.maxScrollX;
50 }
51
52 if ( newY > 0 ) {
53 newY = 0;
54 } else if ( newY < this.maxScrollY ) {
55 newY = this.maxScrollY;
56 }
57
58 this.scrollTo(newX, newY, 0);
59
60// INSERT POINT: _wheel
61 },