Drag and move more than one element at once (element grouping?)

147 views
Skip to first unread message

Tobi

unread,
Aug 20, 2009, 6:44:51 AM8/20/09
to Raphaël
Hi!

First of all this library looks amazing, thank you!

I am trying to create a simple browser based workflow editor. The
Graffle demo looks fantastic and almost like what I am looking for,
except that the drag event handler only references the object that has
been clicked on.
I want to move more than one object at a time, i.e. a rectangle that I
am attaching the event to plus other items (text and image) inside the
rectangle.

So by attaching the dragger event to the rect ...

box = r.rect(150, 150, 120, 40, 10);
box.node.style.cursor = "move";
box.mousedown(dragger);

========================

var dragger = function (e) {
isDrag = this;
isDrag.dx = e.clientX;
isDrag.dy = e.clientY;
isDrag.animate({"fill-opacity": .2}, 500);
e.preventDefault && e.preventDefault();
};

The passed event e only references the source of the click (one single
element), but I want to move not only a single rectangle but also
items within it.

I tried using sets but the event still only picks up the item that has
been clicked on (even if the event is attached to the whole set).

I thought of creating a custom rect that references the items inside
and attaching the event to it so that i can just move the referenced
items together with the rect, but is there a better way?
Somehow I think I am making things more complicated as they are.

Thanks a lot!
Tobi.

charles thomas

unread,
Aug 23, 2009, 12:39:05 PM8/23/09
to raph...@googlegroups.com
T
 
Use .set();
 
You could go to my site at:
 
and scroll down to:
Drag and Drop:Aggregate
 
which takes you to the drag and drop example. This is very basic but you can use the working demo there and compare it in all browser types...
 
 

--- On Thu, 8/20/09, Tobi <tob...@gmail.com> wrote:

Instant message from any web browser! Try the new Yahoo! Canada Messenger for the Web BETA

Tobi

unread,
Aug 24, 2009, 4:43:39 AM8/24/09
to Raphaël
Hi Charles!

Thank you very much for your help! :-)

I now got it working by modifying the dragger eventhandler,
but this looks much more elegant!

Cheers!
Tobias.
>       __________________________________________________________________
> Connect with friends from any web browser - no download required. Try the new Yahoo! Canada Messenger for the Web BETA athttp://ca.messenger.yahoo.com/webmessengerpromo.php
Reply all
Reply to author
Forward
0 new messages