继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

小程序小记1:按钮/view点击事件和长按事件

2018-08-20 22:57:2011994浏览

祁聪

1实战 · 22手记 · 12推荐
TA的实战
<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("长按");  
  },


打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP