Real wheel and touchmove listeners on the race programme: passive or not, preventDefault, heavy work; cancelable, defaultPrevented and the passive default on…
Why it matters
One heavy touchmove listener that is not passive is enough to make scrolling on a phone stutter: every touch waits for your JavaScript. The other way round, preventDefault() in a passive listener is quietly ignored, and a listener on window or body is already passive by default.
The key idea
passive is a promise: "I will not cancel"
Common mistakes
A heavy touchmove listener without passive Every touch waits for your JavaScript to finish, and scrolling on a phone stutters. If the listener only reads the position, add { passive: true }; move the heavy work to requestAnimationFrame or off the main thread.
Calling preventDefault() in a passive listener Ignored: defaultPrevented stays false, and Chrome writes a warning in the Console. If you really must cancel the scroll or zoom, use { passive: false }, or CSS touch-action for touch.
Thinking every listener is passive automatically Only wheel, touchstart and touchmove (and mousewheel) on window, document, the root element and body are passive by default. Listeners on any other element still hold the scroll until you write { passive: true }.
Try it in this playground
Scroll with passive: false and preventDefault() The list is held: defaultPrevented true.
Switch to passive: true, scroll again preventDefault() ignored, the list moves.
Give the listener 50 ms of work See its bars on the main thread’s lane.
Test the browser’s default On window and body a listener with no options is already passive.