Skip to content

Instantly share code, notes, and snippets.

Last active Apr 9, 2022
What would you like to do?
Draggable window in _hyperscript
-- Usage: _="install Draggable(dragHandle: .titlebar in me)"
behavior Draggable(dragHandle)
if no dragHandle set the dragHandle to me
on pointerdown(clientX, clientY) from dragHandle
halt the event
trigger draggable:start -- hooks, e.g. for adding a drop shadow while dragging
measure my x, y
set xoff to clientX - x
set yoff to clientY - y
repeat until event pointerup from document
wait for pointermove(pageX, pageY) or
pointerup (pageX, pageY) from document
add { left: ${pageX - xoff}px; top: ${pageY - yoff}px; }
trigger draggable:move
trigger draggable:end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment