JavaScript节流

2020-05-06  本文已影响0人  利麦乐

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)

}

上一篇下一篇

猜你喜欢

热点阅读