美文网首页微信小程序
微信小程序绑定长按与单击事件

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

作者: 雅雅的前端工作学习 | 来源:发表于2019-01-22 10:04 被阅读0次

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

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

其中

  • bindtouchstart:触屏开始时间
  • bindtouchend :触屏结束时间
  • bindlongtap:绑定长按事件
  • catchtap:单击事件

长按事件会触发单击事件,文档中说不会,操作中确实是触发了,所以在单击事件中加个判断,当触屏时间小于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){
      单击事件内容
   }
}

完成!亲测可用

相关文章

网友评论

    本文标题:微信小程序绑定长按与单击事件

    本文链接:https://www.haomeiwen.com/subject/rxzkjqtx.html