htc 16cc5955fb 框架搭建和登录模块页面画写 | 11 kuukautta sitten | |
---|---|---|
.. | ||
index.d.ts | 11 kuukautta sitten | |
index.js | 11 kuukautta sitten | |
license | 11 kuukautta sitten | |
package.json | 11 kuukautta sitten | |
readme.md | 11 kuukautta sitten |
Delay function calls until a set time elapses after the last invocation
npm install debounce
import debounce from 'debounce';
function resize() {
console.log('height', window.innerHeight);
console.log('width', window.innerWidth);
}
window.onresize = debounce(resize, 200);
(You can also use const debounce = require('debounce')
)
To later clear the timer and cancel currently scheduled executions:
window.onresize.clear();
To execute any pending invocations and reset the timer:
window.onresize.flush();
Creates a debounced function that delays execution until wait
milliseconds have passed since its last invocation.
Set the immediate
option to true
to invoke the function immediately at the start of the wait
interval, preventing issues such as double-clicks on a button.
The returned function has a .clear()
method to cancel scheduled executions, and a .flush()
method for immediate execution and resetting the timer for future calls.