Skip to content

Instantly share code, notes, and snippets.

@thedvlprs
Last active May 30, 2019 17:36
Show Gist options
  • Save thedvlprs/1f210eaafef2452d9cdc9ba93256ddcb to your computer and use it in GitHub Desktop.
Save thedvlprs/1f210eaafef2452d9cdc9ba93256ddcb to your computer and use it in GitHub Desktop.
Задержка при наступлении события (обычно используется в серии однотипных событий - mousemove, dragover и т.д.)
function holdBeforeFired(funcToFire, holdTime){
let hold = false, _this, _arguments;
return function action(){
if (hold) { _this = this; _arguments = arguments; return; }
hold = true;
funcToFire.apply(this,arguments);
setTimeout(()=>{
hold = false;
if (_arguments) {
action.apply(_this, _arguments);
_this = _arguments = null;
}
}, holdTime);
}
}
// Задержка при наступлении события (обычно используется в серии однотипных событий - mousemove, dragover и т.д.)
// Примерно посмотреть что это можно здесь - http://demo.nimius.net/debounce_throttle/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment