Skip to content

Debounce functions. Useful for implementing behavior that should only happen after a repeated action has completed.

Notifications You must be signed in to change notification settings

ponciusz/debounce

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

debounce

Useful for implementing behavior that should only happen after a repeated action has completed.

Installation

$ component install component/debounce

Or in node:

$ npm install debounce

Example

var debounce = require('debounce');
window.onresize = debounce(resize, 200);

function resize(e) {
  console.log('height', window.innerHeight);
  console.log('width', window.innerWidth);
}

API

debounce(fn, wait, [ immediate || false ])

Creates and returns a new debounced version of the passed function that will postpone its execution until after wait milliseconds have elapsed since the last time it was invoked.

Pass true for the immediate parameter to cause debounce to trigger the function on the leading edge instead of the trailing edge of the wait interval. Useful in circumstances like preventing accidental double-clicks on a "submit" button from firing a second time.

License

MIT

About

Debounce functions. Useful for implementing behavior that should only happen after a repeated action has completed.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 86.3%
  • HTML 11.2%
  • Makefile 2.5%