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

posted @ 2017-07-14 17:50  郑闯  阅读(157)  评论(0编辑  收藏  举报