Menu

You're Writing Mouse and Touch Handlers. Pointer Events Does Both.
📰

You're Writing Mouse and Touch Handlers. Pointer Events Does Both.

DEV Community: frontend·Parsa J·16 days ago
#1tFoZdbL
#devtofrontend#devto#dev#touch#drag
Reading 0:00
15s threshold

The demo went great. Drag the card, it follows your cursor, drop it anywhere — smooth, on every laptop in the room. Then someone picks up their phone, drags a thumb across the card — and nothing happens. No movement, no feedback, like the card isn't even listening.

You didn't write a buggy drag handler. You wrote half of one.

box . addEventListener ( ' mousedown ' , ( e ) => { dragging = true ; offsetX = e . clientX - box . offsetLeft ; offsetY = e . clientY - box . offsetTop ; });

box . addEventListener ( ' mousemove ' , ( e ) => { if ( ! dragging ) return ; box . style . left = ` ${ e . clientX - offsetX } px` ; box . style . top = ` ${ e . clientY - offsetY } px` ; });

box .…

Continue reading — create a free account

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