[ 2 posts ]

Ryan Gee

  • Username: rgee
  • Joined: Tue Aug 02, 2011 7:11 am
  • Posts: 4
  • GitHub: rgee
  • Gists: rgee
  • Offline
  • Profile

Animating a cloned DD Proxy on drag:end

Post Posted: Sat Dec 17, 2011 8:35 am
+0-
Let's say I have a grid of images and I want the user to be able to drag them around. There are some valid and invalid drop targets as well.

I used DD Proxy with cloneNode: true to let the user drag around the image. On drag:start I set the visibility of the original node to hidden to give the illusion that they're dragging the real one, but here's where it gets complicated:

If the user drops on an invalid zone, I want to animate the drag proxy back to the original position of the image, then unset the visibility of the original image.

This will not work when using cloneNode: true because the DD Proxy plugin listens to the DragDropManager's drag:end, then removes the cloned proxy from the DOM only if cloneNode is true. This happens before my DragDelegate's drag:end is fired, so I can't jump in before Proxy runs its drag:end handler, stop propagation, do my animation then when it completes, re-fire.

I could potentially hook into DDM's drag:end, but this functionality only pertains to this particular part of the page and there may be multiple draggable elements that may or may not have DD Proxy plugged in.

What's a clean way to handle the animation of cloned drag proxies on drag:end?

EDIT: I figured out a workaround, but I don't really like it. On drag:start, I manually copy over the styles I want the proxy to have. This will quickly get annoying when I change what styles comprise that set! However, it does work. The proxy animates to the drop zone if the user drops on it, and back to its host's starting position if the user drops anywhere else.

Fiddle: http://jsfiddle.net/yLKM6/3/

Ryan Regalado

  • Username: predikt
  • Joined: Mon Dec 17, 2012 9:57 am
  • Posts: 1
  • GitHub: design48
  • Gists: design48
  • Offline
  • Profile

Re: Animating a cloned DD Proxy on drag:end

Post Posted: Mon Dec 17, 2012 10:24 am
+0-
Thanks for posting the jsfiddle code rgee. This helped me a lot in a project that I have a similar use case for.

In terms of setting the styles easier, I found just defining a css class and adding/removing from the nodes helped a great deal as it was just one line of code in the js file.
  [ 2 posts ]
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum