Skip to content

防抖节流相关整理 #195

@ckinmind

Description

@ckinmind

参考资料

window.addEventListener("scroll", throttle(() => console.log("我在滚我在滚!")))

function throttle(fn, interval = 500) {
  let run = true;

  return function () {
    if (!run) return;
    run = false;
    setTimeout(() => {
      fn.apply(this, arguments);
      run = true;
    }, interval);
  };
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions