admin管理员组文章数量:1432359
Basically I have an svg "SecondSVG" into an svg "FirstSVG" into an svg "MainSVG".Every svg has its own ViewBox. This page can be loaded anywhere on the screen by another page.
So basically how can i find the screen x for viewBox for"SecondSVG" knowing that this svg can be loaded basically anywhere based on the calling page?
event.clientX gives myself the x coordinate for the screen. If I don't know the coordinate for ViewBox of "SecondSVG" then how can I find out the x coordinate inside the ViewBox of "SecondSVG"?
I am using Firefox 3.6.3 and I do have an event object from which I can extract clientX, clientY and other coordinates that are relative to the screen. However what I need are the coordinates inside the ViewBox.
Basically I have an svg "SecondSVG" into an svg "FirstSVG" into an svg "MainSVG".Every svg has its own ViewBox. This page can be loaded anywhere on the screen by another page.
So basically how can i find the screen x for viewBox for"SecondSVG" knowing that this svg can be loaded basically anywhere based on the calling page?
event.clientX gives myself the x coordinate for the screen. If I don't know the coordinate for ViewBox of "SecondSVG" then how can I find out the x coordinate inside the ViewBox of "SecondSVG"?
I am using Firefox 3.6.3 and I do have an event object from which I can extract clientX, clientY and other coordinates that are relative to the screen. However what I need are the coordinates inside the ViewBox.
Share Improve this question asked May 28, 2010 at 16:10 Adrian BVAdrian BV 311 silver badge3 bronze badges 3- That's strange, the event should give you coordinates local to the target element. I've had good success with this in recent Firefox. Can you link to a page that illustrates this behaviour? – jbeard4 Commented Aug 5, 2010 at 1:20
- I am having the same issue. Did you manage to shed any light on this subject? – Adam Holmes Commented Mar 1, 2011 at 16:22
- 1 Im not getting you, are you trying to convert screen coordinates (clientX, clientY) to SVG coordinates?! – Cipi Commented Apr 12, 2011 at 13:52
1 Answer
Reset to default 6function click(evt)
{
var root = document.getElementById('your svg');
var uupos = root.createSVGPoint();
uupos.x = evt.pageX;
uupos.y = evt.pageY;
var ctm = evt.target.getScreenCTM();
if (ctm = ctm.inverse())
uupos = uupos.matrixTransform(ctm);
///the new x y are : uupos.x , uupos.y
}
本文标签: javascriptSVGFrom Window coordinates to ViewBox coordinatesStack Overflow
版权声明:本文标题:javascript - SVG - From Window coordinates to ViewBox coordinates - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745595721a2665466.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论