propagate mobile swipe gestures to page where appropriate
This commit is contained in:
parent
9b3301fd0c
commit
931be25635
@ -28,6 +28,7 @@
|
|||||||
var defaultSettings = {
|
var defaultSettings = {
|
||||||
wheelSpeed: 1,
|
wheelSpeed: 1,
|
||||||
wheelPropagation: false,
|
wheelPropagation: false,
|
||||||
|
swipePropagation: true,
|
||||||
minScrollbarLength: null,
|
minScrollbarLength: null,
|
||||||
maxScrollbarLength: null,
|
maxScrollbarLength: null,
|
||||||
useBothWheelAxes: false,
|
useBothWheelAxes: false,
|
||||||
@ -336,6 +337,33 @@
|
|||||||
return true;
|
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() {
|
function bindMouseWheelHandler() {
|
||||||
var shouldPrevent = false;
|
var shouldPrevent = false;
|
||||||
|
|
||||||
@ -713,8 +741,10 @@
|
|||||||
startTime = currentTime;
|
startTime = currentTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
e.stopPropagation();
|
if (shouldPreventDefaultSwipe(differenceX, differenceY)) {
|
||||||
e.preventDefault();
|
e.stopPropagation();
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function touchEnd(e) {
|
function touchEnd(e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user