Skip to content

Instantly share code, notes, and snippets.

@sukhikh18
Last active March 21, 2023 19:31
Show Gist options
  • Save sukhikh18/0af4631832e52e921a444b5cb223cef1 to your computer and use it in GitHub Desktop.
Save sukhikh18/0af4631832e52e921a444b5cb223cef1 to your computer and use it in GitHub Desktop.
Скрипт выполняющий функцию с задержкой после ввода #JS
const keyupDebounce = function(input, callback, doneTypingInterval = 500) { // interval in ms
if (!input) return false;
let typingTimeoutTimer; // timer identifier
// Start the countdown on input/keyup
input.addEventListener('input', e => {
clearTimeout(typingTimeoutTimer)
// user is "finished typing" do something
typingTimeoutTimer = setTimeout(() => callback(), doneTypingInterval)
});
// Reset the countdown on keydown
input.addEventListener('keydown', e => clearTimeout(typingTimeoutTimer))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment