Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Event when two SVG elements touch

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?

like image 686
mortalc Avatar asked Mar 22 '11 19:03

mortalc


People also ask

Can I put an SVG inside another SVG?

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.

Can you nest SVG elements?

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.

How do you click in SVG elements?

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.

What is the G tag in SVG?

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.


2 Answers

There are actually four methods available on the outermost SVG element for intersection handling in the SVG 1.1 DOM:

  1. getIntersectionList
  2. getEnclosureList
  3. checkIntersection
  4. checkEnclosure

Unfortunately I think the cross-browser support for these methods is still not great.

like image 108
Erik Dahlström Avatar answered Oct 07 '22 16:10

Erik Dahlström


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.

like image 24
Mike Baranczak Avatar answered Oct 07 '22 18:10

Mike Baranczak