element.animate(): Animations Without a Stylesheet Round-Trip
The Web Animations API runs keyframe animations from JavaScript with play, pause, reverse and a finished promise - no class juggling, no injected style tags.
Software Engineer
I build web applications and share what I learn along the way.
Step-by-step programming tutorials on PHP, JavaScript, Laravel, WordPress and more.
The Web Animations API runs keyframe animations from JavaScript with play, pause, reverse and a finished promise - no class juggling, no injected style tags.
While a modal is open, the page behind it should not be clickable, tabbable or readable by screen readers. inert does all three - focus traps become one line.
dataset gives JavaScript typed-ish access to data attributes, CSS can select on them and even display them with attr() - one mechanism, three languages, zero coupling.
innerHTML += in a loop is quadratic destruction. The platform has three precise tools for bulk DOM work, and knowing which to grab is most of the performance.
block: "center", preventScroll on focus(), the new scrollend event - the scroll-control details that make custom UI feel native instead of jumpy.
Window resize listeners cannot see a sidebar collapsing or a panel being dragged wider. ResizeObserver watches the element itself - the JS half of container-based design.
That floating "tweet this quote" button on Medium-style sites is the Selection API plus one event. Here is the whole thing, popover positioning included.
Store state against DOM nodes, cache per-object computations, keep private data - WeakMap does all three and lets the garbage collector clean up behind you.
Buttons work until the list refreshes over AJAX, then silently stop. Delegated events fix it permanently - and the same pattern is two lines in vanilla JS.
Focus trapping, Escape to close, a backdrop, top-layer stacking above every z-index - the native dialog element does all of it with zero JavaScript dependencies.
When a third-party script injects, moves or mangles your markup, you cannot patch their code - but you can watch the DOM itself and react the instant it changes.
Scroll listeners fire hundreds of times per second and need throttling, math and luck. IntersectionObserver watches a sentinel element and calls you exactly when it matters.