Is it possible in SVG, using any method, to call an even if two specific elements touch? Or would I have to code the long way, and figure out if their borders touch with complicated maths?
The SVG format allows for the nesting of SVG graphics. It is possible for an “<svg>” elements, to be placed within another “<svg>” element. Though, within a nesting, the absolute placement is limited to the respective parent “<svg>” element.
Nesting or “layering” SVGs allows you to position parts of the SVG relative to the changing viewport, while maintaining the elements' aspect ratio. So the image adapts without distorting the elements inside it.
To click the element with svg, we should identify the element then utilize the Actions class. We shall first move to that element with the moveToElement method and then apply the click method on it. Finally, to actually perform the action, we have to use the build and execute methods.
The <g> SVG element is a container used to group other SVG elements. Transformations applied to the <g> element are performed on its child elements, and its attributes are inherited by its children. It can also group multiple elements to be referenced later with the <use> element.
There are actually four methods available on the outermost SVG element for intersection handling in the SVG 1.1 DOM:
getIntersectionList
getEnclosureList
checkIntersection
checkEnclosure
Unfortunately I think the cross-browser support for these methods is still not great.
I don't think there are any built-in methods, but this guy wrote a Javascript library that detects collisions:
http://www.kevlindev.com/geometry/2D/intersections/index.htm
Looks pretty slick. It doesn't work in Firefox 3.6, but works in Chrome.
EDIT:
OK, there actually is a built-in method, but I don't know if it can be applied to anything besides rectangles. Erik Dahlström, the author of that post, hangs out on Stackoverflow, so he might have something to say about this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With