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

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/quasimodo_es/article/details/81901989
<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("长按");  
},

个人微信号 qicong88 ,欢迎来聊

猜你喜欢

转载自blog.csdn.net/quasimodo_es/article/details/81901989