Hand over the code!
Inside Raphael, this is simpler using toBack() and toFront() :
raphElement.toBack() // Move this element below/behind all others raphElement.toFront() // Move this element above/in front of all others
More details
SVG uses the “artist model” when drawing objects: elements that appear later in the document are drawn after (on top) the elements that appear earlier in the document. To change the splitting of elements, you must reorder the elements in the DOM using appendChild or insertBefore or the like .
Here you can see an example: http://phrogz.net/SVG/drag_under_transformation.xhtml
- Drag the red and blue objects so that they overlap.
- Click on each object and see how it is pushed up. (However, yellow circles should always be visible.)
The reordering of elements in this example is done by lines 93/94 of the source code:
el.addEventListener('mousedown',function(e){ el.parentNode.appendChild(el);
When the mouse is clicked on an element, it moves as the last element of all its brothers and sisters, forcing it to draw the last one, “on top” of all the others.
Phrogz Jul 05 2018-11-11T00: 00Z
source share