var throttle = function (fn,interval) {
var timer, //定时器
firstTime = true; //是否第一次调用
return function () {
var args = arguments,
__me = this;
if (firstTime){
fn.apply(__me,args)
return firstTime = false
}
if (timer){
return false
}
timer = setTimeout(function () {
clearTimeout(timer)
timer = null
fn.apply(__me,args)
},interval)
}
};
window.onresize = throttle(function () {
console.log('resize,500ms')
},500);
【JS】实现函数节流
最新推荐文章于 2024-05-11 18:28:59 发布