首页 > 技术文章 > 解决红米等手机(移动端)无法触发touchend事件

hubgit 2016-09-06 17:28 原文

触屏事件的简单描述:

 

js的触屏事件,主要有三个事件:touchstart,touchmove,touchend。

这三个事件最重要的属性是 pageX和 pageY,表示X坐标,Y坐标。
touchstart=在触摸开始时触发事件
touchend=在触摸结束时触发事件
touchmove=这个事件比较奇怪,按道理在触摸到过程中不断激发这个事件才对,但是在我的 Android 1.5 中,在 touchstart 激发后激发一次,然后剩余的都和 touchend 差不多同时激发。
这三个事件都都有一个 timeStamp 的属性,查看 timeStamp 属性,可以看到顺序是 touchstart -> touchmove ->touchmove -> … -> touchmove ->touchend。

 

触屏事件的问题:

 

如果触发了 touchmove, touchend 就不会被触发了, 而且 touchmove 没有持续触发。

 

解决方法:

 

只要在 touchstart 的时候调用下 event.preventDefault(); 即可让其他事件都正常被触发了!

 

推荐阅读