Last active
May 30, 2019 17:36
-
-
Save thedvlprs/1f210eaafef2452d9cdc9ba93256ddcb to your computer and use it in GitHub Desktop.
Задержка при наступлении события (обычно используется в серии однотипных событий - mousemove, dragover и т.д.)
This file contains hidden or 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 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