Created
September 21, 2020 10:39
-
-
Save victorpavlov/dffffb216914cbd73ea639f79b4a4dfb to your computer and use it in GitHub Desktop.
Event Delay: https://coderatings.io/snippet/147/how-to-delay-the-keyup-handler-until-the-user-stops-typing-in-javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function delay(callback, ms) { | |
var timer = 0; | |
return function() { | |
var context = this, args = arguments; | |
clearTimeout(timer); | |
timer = setTimeout(function () { | |
callback.apply(context, args); | |
}, ms || 0); | |
}; | |
} | |
// Example usage: | |
$('input').keyup(delay(function (e) { | |
console.log('Time elapsed!', this.value); | |
}, 500)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment