码迷,mamicode.com
首页 > 微信 > 详细

微信小程序使用函数防抖解决重复点击消耗性能问题

时间:2019-09-11 10:08:30      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:rip   amp   防止   性能   触发点   click   double   tap   apt   

wxml:

<view bindtap="doubleTap" bindtouchstart="touchStart" bindtouchend="touchEnd">click me</view>

   js:

 // 防止重复点击
  touchStart(e) {
   
    this.touchStartTime = e.timeStamp;
  },
  touchEnd(e) {
    this.touchEndTime = e.timeStamp;
  },
  doubleTap(e) {
    var vm = this;
    // 控制点击事件在350ms内触发,加这层判断是为了防止长按时会触发点击事件
    if (vm.touchEndTime - vm.touchStartTime < 350) {
      // 当前点击的时间
      var currentTime = e.timeStamp;
      var lastTapTime = vm.lastTapTime;
      // 更新最后一次点击时间
      vm.lastTapTime = currentTime;
      // 如果两次点击时间在300毫秒内,则认为是双击事件
      if (currentTime - lastTapTime > 300) {
        // do something 点击事件具体执行那个业务
       
      }
    }
  }

  

微信小程序使用函数防抖解决重复点击消耗性能问题

标签:rip   amp   防止   性能   触发点   click   double   tap   apt   

原文地址:https://www.cnblogs.com/mmykdbc/p/11504327.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!