Skip to content

Commit 4e2e63e

Browse files
committed
#16 don't stop wheel, touch and keyboard scroll events propagation when scrollbar position hasn't changed
1 parent 8210504 commit 4e2e63e

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

jquery.custom-scrollbar.js

+23-11
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,10 @@
251251
var _this = this;
252252
this.scrollable.$element.mousewheel(function (event, delta, deltaX, deltaY) {
253253
if (_this.enabled) {
254-
_this.mouseWheelScroll(deltaX, deltaY);
255-
return false;
254+
if (_this.mouseWheelScroll(deltaX, deltaY)) {
255+
event.stopPropagation();
256+
event.preventDefault();
257+
}
256258
}
257259
});
258260
},
@@ -364,10 +366,12 @@
364366
touchScroll: function (event) {
365367
if (this.touchScrolling && event.touches && event.touches.length == 1) {
366368
var delta = -this.sizing.mouseDelta(this.scrollEvent, event.touches[0]) * this.scrollable.options.swipeSpeed;
367-
this.scrollOverviewBy(delta);
369+
var scrolled = this.scrollOverviewBy(delta);
368370
this.setScrollEvent(event.touches[0]);
369-
event.stopPropagation();
370-
event.preventDefault();
371+
if (scrolled) {
372+
event.stopPropagation();
373+
event.preventDefault();
374+
}
371375
}
372376
},
373377

@@ -379,7 +383,7 @@
379383
mouseWheelScroll: function (deltaX, deltaY) {
380384
var delta = -this.sizing.wheelDelta(deltaX, deltaY) * this.scrollable.options.wheelSpeed;
381385
if (delta != 0)
382-
this.scrollOverviewBy(delta);
386+
return this.scrollOverviewBy(delta);
383387
},
384388

385389
mouseClickScroll: function (event) {
@@ -393,8 +397,8 @@
393397
keyScroll: function (event) {
394398
var keyDown = event.which;
395399
if (this.enabled && this.isKeyScrolling(keyDown)) {
396-
this.scrollOverviewBy(this.keyScrollDelta(keyDown));
397-
event.preventDefault();
400+
if (this.scrollOverviewBy(this.keyScrollDelta(keyDown)))
401+
event.preventDefault();
398402
}
399403
},
400404

@@ -406,8 +410,12 @@
406410
this.scrollPercent = thumbPosition / this.maxThumbPosition;
407411
var overviewPosition = (thumbPosition * this.maxOverviewPosition) / this.maxThumbPosition;
408412
this.setScrollPosition(overviewPosition, thumbPosition);
409-
if (oldScrollPercent != this.scrollPercent)
413+
if (oldScrollPercent != this.scrollPercent) {
410414
this.triggerCustomScroll(oldScrollPercent);
415+
return true
416+
}
417+
else
418+
return false;
411419
},
412420

413421
thumbPosition: function () {
@@ -416,7 +424,7 @@
416424

417425
scrollOverviewBy: function (delta) {
418426
var overviewPosition = this.overviewPosition() + delta;
419-
this.scrollOverviewTo(overviewPosition, false);
427+
return this.scrollOverviewTo(overviewPosition, false);
420428
},
421429

422430
overviewPosition: function () {
@@ -432,8 +440,12 @@
432440
this.setScrollPositionWithAnimation(overviewPosition, thumbPosition);
433441
else
434442
this.setScrollPosition(overviewPosition, thumbPosition);
435-
if (oldScrollPercent != this.scrollPercent)
443+
if (oldScrollPercent != this.scrollPercent) {
436444
this.triggerCustomScroll(oldScrollPercent);
445+
return true;
446+
}
447+
else
448+
return false;
437449
},
438450

439451
positionOrMax: function (p, max) {

0 commit comments

Comments
 (0)