function throttle(fn, delag) {
let delagTime = delag || 200
let timer
let last
return function(){
let self = this
let args = arguments
let now = +new Date()
if (last && now - last < delagTime){
clearTimeout(timet)
timer = setTimeout(function(){
last = now
fn.apply(self, args)
},delagTime)
} else {
last = now
fn.apply(self, args)
}
}
}
网友评论