组件点击事件和长按事件

阅读量: 276 编辑

组件点击事件和长按事件

.wxml

<button 
bindtouchstart="bindtouchstart" 
bindtouchend="bindtouchend" 
bindlongpress="bindlongpress" 
bindtap="bindtap">
点击/长按</button> 

.js

//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("长按");  
},