美文网首页
JavaScript节流

JavaScript节流

作者: 利麦乐 | 来源:发表于2020-05-06 14:48 被阅读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)

    }

    相关文章

      网友评论

          本文标题:JavaScript节流

          本文链接:https://www.haomeiwen.com/subject/fskwghtx.html