Skip to content

Instantly share code, notes, and snippets.

@philjackson
Created October 30, 2018 18:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philjackson/fce0427ddc3e5dff6b8a54e6c02b8d23 to your computer and use it in GitHub Desktop.
Save philjackson/fce0427ddc3e5dff6b8a54e6c02b8d23 to your computer and use it in GitHub Desktop.
Drag and drop with Reagent and Interact.js
(defn draggable []
(let [pos (atom [0 0])]
(reagent/create-class
{:render
#(let [[x y] @pos]
[:div.d {:style {:transform (str "translate(" x "px," y "px)")}}
"I can be dragged"])
:component-did-mount
(fn [this]
(.draggable (js/interact (reagent/dom-node this))
#js {:onmove (fn [ev]
(let [[x y] @pos
new-x (+ (.-dx ev) x)
new-y (+ (.-dy ev) y)]
(reset! pos [new-x new-y])))}))})))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment