首页 > 其他 > 详细

连续点击按钮跳页面重复

时间:2020-01-02 16:56:00      阅读:85      评论:0      收藏:0      [点我收藏+]

https://www.jianshu.com/p/12c7307a02c2

    if (gapTime == null || gapTime == undefined) {
      gapTime = 1500
    }
    let _lastTime = null
    return function () {
      let _nowTime = + new Date()
        if (_nowTime - _lastTime > gapTime || !_lastTime) {
            fn()
            _lastTime = _nowTime
        }
    }
}
 module.exports = {
  throttle: throttle
}

下面的更好

unction throttle(fn,gapTime) {
    if (gapTime == null || gapTime == undefined) {
      gapTime = 1500
    }
    let _lastTime = null
    return function () {
      let _nowTime = + new Date()
        if (_nowTime - _lastTime > gapTime || !_lastTime) {
            // 将this和参数传给原函数
            fn.apply(this,arguments)
            _lastTime = _nowTime
        }
    }
}

 

连续点击按钮跳页面重复

原文:https://www.cnblogs.com/dianzan/p/12133519.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!