Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta name="description" content="debounce 饥人谷" />
  <meta charset="utf-8">
  <title>函数防抖</title>
</head>
<body>
  <h1>函数防抖</h1>
  <h1>函数防抖</h1>
  <h1>函数防抖</h1>
  <h1>函数防抖</h1>
  <h1>函数防抖</h1>
  <h1>函数防抖</h1>
  <h1>函数防抖</h1>
  <h1>函数防抖</h1>
  <h1>函数防抖</h1>
  <h1>函数防抖</h1>
  <h1>函数防抖</h1>
  <h1>函数防抖</h1>
  <h1>函数防抖</h1>
  <h1>函数防抖</h1>
  <h1>函数防抖</h1>
  <h1>函数防抖</h1>
  <h1>函数防抖</h1>
  <h1>函数防抖</h1>
  <h1>函数防抖</h1>
  <h1>函数防抖</h1>
  <h1>函数防抖</h1>
</body>
</html>
 
function debounce(fn, wait) {
  let timer = null
  return function() {
    if (timer) {
      clearTimeout(timer)
    }
    timer = setTimeout(() => fn.apply(this, arguments), wait)
  }
}
function fn() {
  console.log("防抖")
}
fn = debounce(fn, 1000)
document.body.onscroll = function() {
  fn()
}
Output

This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account

Dismiss x
public
Bin info
anonymouspro
0viewers