Menu

Before and after slider in React, accessible and draggable
📰

Before and after slider in React, accessible and draggable

DEV Community: react·Marco Schulz·11 days ago
#5V2euhmd
#devtoreact#devto#dev#handle#slider
Reading 0:00
15s threshold

Roofers, painters, landscapers and remodelers all have the same proof: a photo from before the job and a photo from after. Put the two side by side and the eye wanders. Put them in one frame with a handle the visitor drags and the eye follows the handle. That is why the comparison slider earns a spot on every home services site I build, and why I spent more time on the Before / after slider in Facade than its size suggests. Most of that time went into things you cannot see in a demo: touch, keyboard and screen readers.

Pointer events, not mouse events

The first version of every comparison slider on the internet listens to mousedown , mousemove and mouseup . Then someone opens it on a phone and nothing happens, so touchstart and touchmove get bolted on, and now there are two code paths that drift apart.

Pointer events replace both. onPointerDown , onPointerMove and onPointerUp fire for mouse, touch and pen with the same event shape, and clientX means the same thing in all three.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.