Home / Web programming, webdev / JavaScript / javascript snippets edit
Try Documentalist, my app that offers fast, offline access to 190+ programmer API docs.

debounce resize event with requestAnimationFrame
function runDebounced(f) {
  let timeout = null;
  const f = function() {
    if (timeout) {
      window.cancelAnimationFrame(timeout);
    }
    timeout = window.requestAnimationFrame(f);
  }
  f();
}

window.addEventListener('resize', function(e) {
  function f() {
    console.log("resize:", e);
  }
  runDebounced(f);
}, false);

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:

Need fast, offline access to 190+ programmer API docs? Try my app Documentalist for Windows