image.png

    触摸引发的事件,有以下几种。可以通过TouchEvent.type属性,查看到底发生的是哪一种事件

    1. touchstart:用户开始触摸时触发,它的target属性返回发生触摸的元素节点
    2. touchend:用户不再接触触摸屏时触发
    3. touchmove:用户移动触摸点时触发
    4. touchcancel:系统取消touch事件的时候触发(使用率低)

    ⚠️注意:上述所有事件,都必须用DOM2级事件处理

    1. var box = document.getElementById("box");
    2. box.addEventListener("touchend",function(){
    3. console.log("抬起来了");
    4. })
    5. box.addEventListener("touchstart",function(e){
    6. console.log("触摸屏幕",e);
    7. })
    8. box.addEventListener("touchmove",function(){
    9. console.log("移动");
    10. })