最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Event when two SVG elements touch - Stack Overflow

programmeradmin0浏览0评论

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?

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?

Share Improve this question edited Mar 22, 2011 at 22:30 Erik Dahlström 61k12 gold badges122 silver badges140 bronze badges asked Mar 22, 2011 at 19:23 mortalcmortalc 5751 gold badge5 silver badges9 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 14

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.

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.

发布评论

评论列表(0)

  1. 暂无评论