var debounce = function (func, wait, lossless) {
var lastTimeout, alreadyDo = false;
if (typeof lossless == 'undefined')
lossless = true;
return function () {
var context = this,
args = arguments;
if (!alreadyDo) {
alreadyDo = true;
setTimeout(function () { alreadyDo = false }, wait);
clearTimeout(lastTimeout);
func.apply(context, args);
} else if (lossless) {
clearTimeout(lastTimeout);
lastTimeout = setTimeout(function () {
func.apply(context, args);
}, wait);
}
};
}
///防抖函数 ///防止事件函数高频执行,间隔wait毫秒执行 ///lossless是否保存最后一次未到间隔时间的执行
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有