Skip to content

Instantly share code, notes, and snippets.

@dz4k

dz4k/Draggable._hs

Last active Jul 25, 2021
Embed
What would you like to do?
Draggable window in _hyperscript
-- Usage: _="install Draggable(dragHandle: .titlebar in me)"
behavior Draggable(dragHandle)
init
if no dragHandle set the dragHandle to me
end
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}`, top: `${pageY - yoff}` }
trigger draggable:move
end
trigger draggable:end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment