Attention
TYPO3 v11 has reached end-of-life as of October 31th 2024 and is no longer being maintained. Use the version switcher on the top left of this page to select documentation for a supported version of TYPO3.
Need more time before upgrading? You can purchase Extended Long Term Support (ELTS) for TYPO3 v11 here: TYPO3 ELTS.
Debounce event
A "debounced event" executes its handler only once in a series of the same events. If the event listener is configured to execute immediately, it's executed right after the first event is fired until a period of time passed since the last event. If its not configured to execute immediately, which is the default setting, the event listener is executed after the period of time passed since the last event fired.
This type of event listening is suitable when a series of the same event is fired, e.g. the mousewheel
or resize
events.
To construct the event listener, the module TYPO3/
must be imported. The constructor
accepts the following arguments:
event
(string) - the event to listen onName callback
(function) - the executed event listener when the event is triggeredwait
(number) - the amount of milliseconds to wait the event listener is either executed or lockedimmediate
(boolean) - defined whether the event listener is executed before or after the waiting time
new DebounceEvent('mousewheel', function (e) {
console.log('Executed 200ms after the last mousewheel event was fired');
}, 200).bindTo(document.body);
new DebounceEvent('mousewheel', function (e) {
console.log('Executed right after the first 200ms after the last mousewheel event was fired');
}, 200, true).bindTo(document.body);