Skip to content

Instantly share code, notes, and snippets.

@dz4k
Last active September 23, 2023 07:18
  • Star 9 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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}px; top: ${pageY - yoff}px; }
trigger draggable:move
end
trigger draggable:end
end
@waldyrious
Copy link

Is this live somewhere that could serve as a demo?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment