添加向左/向右滑动到网页,但使用默认向上/向下滑动

Vec*_*ign 6 html javascript swipe ios

我正在使用padilicious来检测将在iOS和桌面上查看的网页的滑动手势.它可以很好地向我/我网站的上一页和下一页左/右滑动.但是,当向上/向下滑动时,它似乎会覆盖iPhone/iPad中的默认行为.我想要一个向上/向下滑动来滚动页面,当我没有运行时它会这样做.只是让代码忽略向上/向下滑动似乎不起作用.

我一直以来的padilicious代码部分

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;
    }


}
Run Code Online (Sandbox Code Playgroud)

小智 5

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';
    }
}
Run Code Online (Sandbox Code Playgroud)