js 触摸事件 touch

//ban 为某div
let startX = 0;
ban.addEventListener("touchstart",function(){
    //获取初始点击位置
    startX = event.touches[0].pageX;
})
ban.addEventListener("touchmove",function(){
    //获取触摸移动的长度
    moveX = event.touches[0].pageX-startX;
    if(moveX > 30){
        //清除定时器
        clearInterval(t);
        //右移
        r_pic();
        //启动定时器
        t = animation(); 
    }
    if(moveX < -30){
        //清除定时器
        clearInterval(t);
        //左移
        l_pic();
        //启动定时器
        t = animation();
    }
})

原文地址:https://www.cnblogs.com/zheng-chuang/p/7171690.html