11

I'm trying to order Raphael objects. I don't have the option of deciding when the objects are created, but I'd like to make a group of objects appear behind a group of other objects after they've been created. Can anybody help me do this?

Thanks.

So8res
  • 9,856
  • 9
  • 56
  • 86

2 Answers2

12

Group you items in two sets and position the sets relative to each other with insertBefore or insertAfter:

var front = paper.set();
front.push(front1, front2);

var back = paper.set();
back.push(back1, back2);

front.insertBefore(back);

Also if you have your items in arrays you can use apply for convenience:

var frontItems = [front1, front2];
front.push.apply(null, frontItems);
Alin Purcaru
  • 43,655
  • 12
  • 77
  • 90
3

You can use toBack. http://raphaeljs.com/reference.html#toBack

It will put an object behind the other objects regardless of when you created it.

Adam
  • 43,763
  • 16
  • 104
  • 144
  • 1
    Unfortunately this won't work for me. There are some background objects that everything needs to stay in front of, and I'm trying to arrange my foreground objects. There's too many background objects to make repeated use of toBack feasible. – So8res Dec 09 '10 at 00:41