微信小程序

微信小程序绑定长按与单击事件

2019-01-22  本文已影响0人  雅雅的前端工作学习

为需要添加长按事件的组件添加以下四个事件

<view class='oneofnotice' catchtap="onLinkDatail"  bindtouchstart="mytouchstart" bindlongtap="deleteitem" bindtouchend="mytouchend">
  组件中的内容
</view>

其中

长按事件会触发单击事件,文档中说不会,操作中确实是触发了,所以在单击事件中加个判断,当触屏时间小于350ms才会触发单机事件(长按事件在触屏时间大于350ms时会自动触发):

  mytouchstart: function (e) {  //记录触屏开始时间
    this.setData({start:e.timeStamp })
  },
  mytouchend: function (e) {  //记录触屏结束时间
    this.setData({end: e.timeStamp })
  }, 
 deleteitem:function(e) {  长按事件内容   }
 onLinkDatail:function(e) {
   if (_that.data.end - _that.data.start < 350){
      单击事件内容
   }
}

完成!亲测可用

上一篇 下一篇

猜你喜欢

热点阅读