Skip to content

Instantly share code, notes, and snippets.

@fyulistian
Created June 20, 2019 10:01
Show Gist options
  • Save fyulistian/bcfc4ba141c7554d303c493c3d335e6e to your computer and use it in GitHub Desktop.
Save fyulistian/bcfc4ba141c7554d303c493c3d335e6e to your computer and use it in GitHub Desktop.
Type event
// delay on typing
function delay(callback, ms) {
let timer = 0;
return function() {
let context = this, args = arguments;
clearTimeout(timer);
timer = setTimeout(function () {
callback.apply(context, args);
}, ms || 0);
};
}
const TYPING_TIMER_LENGTH = 700;
const $inputSearch = $('#inputSearch');
$inputSearch.keyup(delay(function (e) {
let val = this.value;
// doSimething
// #
}, TYPING_TIMER_LENGTH));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment