admin管理员组文章数量:1200357
I have some objects inside of svg that can be clicked by user.
Is there any way to: - send information about object (id) that was clicked by user to the 'main html document'? - draw from outside document in the svg file.
Probably, my description is unclear,... I want to implement something like this:
- user click on any object inside of svg-image;
- main document will receive id of the clicked object and:
- display some information about that object;
- draw additional object inside of the svg-image.
Questions: how to communication from svg to document and from document to svg?
Thanks a lot, any thoughts are welcome!
P.S. Probably SVG is not the best way do that? What is better then?
EDIT: I saw recommendation regarding use of Raphael,.. but I would like to see 'native' options. (For now I'm analyzing Raphaels implementation to see that, but don't think it is doing exactly what I need).
I have some objects inside of svg that can be clicked by user.
Is there any way to: - send information about object (id) that was clicked by user to the 'main html document'? - draw from outside document in the svg file.
Probably, my description is unclear,... I want to implement something like this:
- user click on any object inside of svg-image;
- main document will receive id of the clicked object and:
- display some information about that object;
- draw additional object inside of the svg-image.
Questions: how to communication from svg to document and from document to svg?
Thanks a lot, any thoughts are welcome!
P.S. Probably SVG is not the best way do that? What is better then?
EDIT: I saw recommendation regarding use of Raphael,.. but I would like to see 'native' options. (For now I'm analyzing Raphaels implementation to see that, but don't think it is doing exactly what I need).
Share Improve this question edited May 11, 2011 at 17:04 Budda asked May 11, 2011 at 15:00 BuddaBudda 18.3k35 gold badges128 silver badges210 bronze badges4 Answers
Reset to default 10See this example for how to get the DOM of a referenced svg from the parent document.
And here's an example of how you can call from an svg file to the parent document.
SVG is very well suited for doing what you describe.
I'd suggest using a library like Raphaël to support your SVG building. You can attach events to DOM objects that you can get through the node
property of an image component.
Raphaël.js is indeed a good solution if you want to stick to SVG / VML. Now you can use canvas (new HTML 5 functionality) as well. Canvas is a new html tag (that can have id, events, ...) that allows you to draw free shapes a bit like SVG does. IE doesn't support canvas natively, of course, and you will need "excanvas.js" (this one or another, but this one works pretty well...) to make it IE compatible.
Only one restriction I know of regarding canvas: using background images makes IE be very slow. I would use Raphaël.js if it was something you'd consider doing.
Good luck
Nobody suggested, but accidentally I've found that svg is already supported by jQuery! http://plugins.jquery.com/project/svg
Probably that is not the best approach, but I will try to work with svg using jquery. And actually, that seems like reasonable
本文标签: javascriptupdate SVG dynamicallyStack Overflow
版权声明:本文标题:javascript - update SVG dynamically - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738537515a2094829.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论