uni-app(小程序)的各种手势,点击事件

1,480 阅读1分钟

uni-app(小程序)的各种手势,点击事件

事件

@click 组件被点击  
@longpress 长按(手指触摸超过350ms)  (微信小程序和H5)
@longtap 长按  (支付宝小程序等)
@tap 点击  
@touchcancel 手指触摸被打断,如来电提醒,弹窗  
@touchend 手指触摸动作结束,如松开按钮  
@touchmove 手指触摸后移动  
@touchstart 手指触摸动作开始

示例

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