Adds a watcher and immediately begins watching.
Disposes of domWatcher.
Removes all dom watchers.
Removes a given watcher by id.
The id of the watcher to remove.
Dry runs a callback by id. This just calls the callback and isn't the actual browser event so no event data will be available when using this method.
watcher.add({
element: element,
callback: ()=> {
console.log('yo');
}
on: 'click',
id: 'yo'
});
watcher.run('yo');
A class that helps with DOM events. The main usecase for this class is to be able to watch the dom and then later remove a group of events all at once.
Basic Usage
Advanced Usage
ResizeObserver
https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver DomWatcher supports resizeObserver. To use it simply, watch the resize of an element that isn't the window. Using window will use the standard window resize events.
MutationObserver
https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver DomWatcher supports mutation observers. You can pass mutation config to the event options.
Debouncing
SmartResize
How can I use this with bom.smartResize? Just use the 'smartResize' event instead.
Culling events only when an element is inview. See example/scroll-demo for actual example.
MatchMedia
https://developer.mozilla.org/en-US/docs/Web/API/Window/matchMedia DomWatcher supports MediaQueryLists that result from calls to matchMedia. That way DomWatcher can be configured to watch for changes across any/all breakpoints a site is designed around.