Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- / Typescript function to throttle frequently occurring events (resize, keydown etc...).
- / Example: document.getElementById("inputBox").addEventListener("keyup", throttle(eventHandler, 300));
- */
- function throttle(callback: () => void, limit: number) {
- var wait = false;
- return () => {
- if (!wait) {
- callback();
- wait = true;
- setTimeout(() => {
- wait = false;
- }, limit);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement