微信小程序点击事件和长按事件

小天天天天    前端    999+ 次    2021-12-23 14:51:18


<button 
bindtouchstart="handleTouchStart" 
bindtouchend="handleTouchEnd" 
bindlongpress="handleLongPress" 
bindtap="handleClick">
点击/长按</button> 
<!-- button 可以换成view-->

//touch start
handleTouchStart: function(e) {    
    this.startTime = e.timeStamp;    
    //console.log(" startTime = " + e.timeStamp);  
},  
 
//touch end
handleTouchEnd: function(e) {    
    this.endTime = e.timeStamp;    
    //console.log(" endTime = " + e.timeStamp);  
},  
 
handleClick: function(e) {    
    //console.log("endTime - startTime = " + (this.endTime - this.startTime));    
    if (this.endTime - this.startTime < 350) {      
    console.log("点击");    
    }  
},  
 
handleLongPress: function(e) {    
//console.log("endTime - startTime = " + (this.endTime - this.startTime));
console.log("长按");  
},

如果你觉得本篇文章对您有帮助,请打赏作者

上一篇: JS里的ArrayBuffer

下一篇: 常用的前端JavaScript方法封装

最新评论

暂无评论

热门文章

最新评论

网站数据

网站文章数:481

今日UV/PV/IP:13/15/13

昨日UV/PV/IP:33/37 /33

TOP