作者:feix760

怎么复现这个问题

​

​

1、首先随意的滑两次,每次滑长一些,不用滑重(碎屏就不好了~~)

​

2、再点击一次,之后立刻停住~

​

Oh, no 你肯定在我说停住之后再点了一下,你觉得你并没有点到~

​

反复试几次仔细发现,原来是要点两次!

​

为什么会这样

​

zepto 发出you tap me的嚎叫可以用下面代码归纳

​

$(document)                                                                      
    .on('touchstart', function() {                                               
        // 打酱油                                                                
    })                                                                           
    .on('touchmove', function() {                                                
        deltaX += XXX;                                                           
        deltaY += XXX;                                                           
    })                                                                           
    .on('touchend', function() {                                                 
        if (deltaX < 30 && deltaY < 30) {                                                                                                                
            // you tap me                                                           
            touch.el && touch.el.trigger(event)                                     
        }                                                                           
        deltaX = deltaY = 0;                                                                                                                              
    })                                                                           
    .on('touchcancel', function() {                                                 
        // 打酱油                                                                   
    });

​

Android 4.4 touch事件

​

长距离的滑动: touchstart - > touchmove(仅一次) -> touchcancel

​

短距离: touchstart - > touchmove(一次) -> touchend

​

事情发展到了这里,去下载最新的zepto发现也只在touchend里做了这件重要的事情

​

deltaX = deltaY = 0;   

哎~

​

看破红尘,上面的都不重要

​

Android 4.4 长距离的滑动touchmove只发生一次是不是让充满爱的FE瞬间变得忧伤了~

​

哈~,其实只需touchmove时e.preventDefault()

​

touchstart - > touchmove(仅一次) -> touchcancel

​

就能变成

​

touchstart - > touchmove(多次) -> touchend

​

(也不再是touchcancel了)

​

​

原文链接:http://ivweb.io/topic/55c5d4c8c222e3af6ce235aa

​

文章来源于腾讯云开发者社区,点击查看原文