Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
249 views
in Technique[技术] by (71.8m points)

javascript - update SVG dynamically

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:

  1. user click on any object inside of svg-image;
  2. 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).

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

See 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...