我正在使用 padilicious 来检测将在 iOS 和桌面上查看的网页的滑动手势。向左/向右滑动我网站的上一页和下一页效果很好。但是,向上/向下滑动时,它似乎覆盖了 iPhone/iPad 中的默认行为。我想要向上/向下滑动来滚动页面,当我没有恶意运行时它会这样做。只是让代码忽略向上/向下滑动似乎不起作用。
我经历过的恶作剧代码段
function processingRoutine() {
var swipedElement = document.getElementById(triggerElementID);
if ( swipeDirection == 'left' ) {
document.location = document.getElementById('nextPage').href;
} else if ( swipeDirection == 'right' ) {
document.location = document.getElementById('prevPage').href;
} else if ( swipeDirection == 'up' ) {
return;
} else if ( swipeDirection == 'down' ) {
return;
}
}
最佳答案
从所有函数中删除 event.preventDefault();
。在函数 processingRoutine() {}
中添加 event.preventDefault();
以获得所需内容。
function processingRoutine() {
var swipedElement = document.getElementById(triggerElementID);
if ( swipeDirection == 'left' ) {
// REPLACE WITH YOUR ROUTINES
//swipedElement.style.backgroundColor = 'orange';
event.preventDefault();
} else if ( swipeDirection == 'right' ) {
// REPLACE WITH YOUR ROUTINES
//swipedElement.style.backgroundColor = 'green';
event.preventDefault();
} else if ( swipeDirection == 'up' ) {
// REPLACE WITH YOUR ROUTINES
//swipedElement.style.backgroundColor = 'maroon';
} else if ( swipeDirection == 'down' ) {
// REPLACE WITH YOUR ROUTINES
//swipedElement.style.backgroundColor = 'purple';
}
}
关于javascript - 添加向左/向右滑动到网页,但使用默认向上/向下滑动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5304340/