propagate mobile swipe gestures to page where appropriate
This commit is contained in:
parent
9b3301fd0c
commit
931be25635
@ -28,6 +28,7 @@
|
||||
var defaultSettings = {
|
||||
wheelSpeed: 1,
|
||||
wheelPropagation: false,
|
||||
swipePropagation: true,
|
||||
minScrollbarLength: null,
|
||||
maxScrollbarLength: null,
|
||||
useBothWheelAxes: false,
|
||||
@ -336,6 +337,33 @@
|
||||
return true;
|
||||
}
|
||||
|
||||
// check if default swipe should be prevented
|
||||
function shouldPreventDefaultSwipe(deltaX, deltaY) {
|
||||
var
|
||||
scrollTop = $this.scrollTop(),
|
||||
scrollLeft = $this.scrollLeft(),
|
||||
magnitudeX = Math.abs(deltaX),
|
||||
magnitudeY = Math.abs(deltaY);
|
||||
|
||||
if (magnitudeY > magnitudeX) {
|
||||
// user is perhaps trying to swipe up/down the page
|
||||
|
||||
if (((deltaY < 0) && (scrollTop === contentHeight - containerHeight)) ||
|
||||
((deltaY > 0) && (scrollTop === 0))) {
|
||||
return !settings.swipePropagation;
|
||||
}
|
||||
} else if (magnitudeX > magnitudeY) {
|
||||
// user is perhaps trying to swipe left/right across the page
|
||||
|
||||
if (((deltaX < 0) && (scrollLeft === contentWidth - containerWidth)) ||
|
||||
((deltaX > 0) && (scrollLeft === 0))) {
|
||||
return !settings.swipePropagation;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function bindMouseWheelHandler() {
|
||||
var shouldPrevent = false;
|
||||
|
||||
@ -713,10 +741,12 @@
|
||||
startTime = currentTime;
|
||||
}
|
||||
|
||||
if (shouldPreventDefaultSwipe(differenceX, differenceY)) {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
}
|
||||
}
|
||||
}
|
||||
function touchEnd(e) {
|
||||
if (!inGlobalTouch && inLocalTouch) {
|
||||
inLocalTouch = false;
|
||||
|
Loading…
Reference in New Issue
Block a user