在 iPad 上 Scrollable 过于敏感的情况下,我需要做类似的事情。以下是我所做的更改,以使其对水平滑动不那么敏感:
// touch event
if (conf.touch) {
var touch = {};
itemWrap[0].ontouchstart = function(e) {
var t = e.touches[0];
touch.x = t.clientX;
touch.y = t.clientY;
};
itemWrap[0].ontouchmove = function(e) {
// only deal with one finger
if (e.touches.length == 1 && !itemWrap.is(":animated")) {
var t = e.touches[0],
deltaX = touch.x - t.clientX,
deltaY = touch.y - t.clientY;
self[vertical && deltaY > 0 || !vertical && deltaX > 0 ? 'next' : 'prev']();
e.preventDefault();
}
};
}
变成
// touch event
if (conf.touch) {
var touch = {};
itemWrap[0].ontouchstart = function(e) {
var t = e.touches[0];
touch.x = t.clientX;
touch.y = t.clientY;
};
itemWrap[0].ontouchmove = function(e) {
// only deal with one finger
if (e.touches.length == 1 && !itemWrap.is(":animated")) {
var t = e.touches[0],
deltaX = touch.x - t.clientX,
deltaY = touch.y - t.clientY;
if(deltaX > 200 || deltaX < -200) { // new line
self[vertical && deltaY > 0 || !vertical && deltaX > 0 ? 'next' : 'prev']();
} // new line
e.preventDefault();
}
};
}
将 200 调整到您希望人们在切换到下一张幻灯片之前必须拖动手指的距离。同样,如果您想控制垂直滚动条,请将新代码中的 deltaX 更改为 deltaY:
if(deltaY > 200 || deltaY < -200) { // new line
self[vertical && deltaY > 0 || !vertical && deltaX > 0 ? 'next' : 'prev']();
} // new line
如果您正在使用 jQuery 工具的最小化版本,您可以使用以下代码:
// horizontal change
if(h > 200 || h < -200) {
b[j && d > 0 || !j && h > 0 ? "next" : "prev"]();
}
// vertical change
if(d > 200 || d < -200) {
b[j && d > 0 || !j && h > 0 ? "next" : "prev"]();
}