zepto點透事件

原因: zepto的tap通過兼聽綁定在document上的touch事件來完成tap事件的模擬的,及tap事件是冒泡到document上觸發的由於click 在移動端會發生300毫秒延遲。當tap點擊後還沒冒泡到document上時,在手指的點擊下會發生click事件!

解決:

方法1:使用github 上的fastclick插件

引入 fastclick.js 

window.addEventListener('load',function(){
    FastClick.attach(document.body)
},false)

或者在 zeptojs 中直接寫

$(function(){
    FastClick.attach(document.body)
});

使用require的話這樣寫

var FastClick = require('fastclick');
FastClick.attach(document.body,options);

 

方法2:使用touchend 代替tap並阻止默認事件preventDefault( );

 

方法3:使用延遲300ms 來處理事件;

$("#cd").on('tap',function(event){
    setTimeout(function(){
        //這裏面寫處理的js
    },320)
    
})

 

方法4:使用css3 的給下層設置pointer-events=true;pointer-events=none;來實現

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章