SVG - 从Window坐标到ViewBox坐标

Adr*_* BV 3 javascript firefox svg

基本上我有一个svg"SecondSVG"进入一个svg"FirstSVG"进入一个svg"MainSVG".每个svg都有自己的ViewBox.此页面可以通过其他页面加载到屏幕上的任何位置.
所以我基本上如何找到"SecondSVG"的viewBox的屏幕x,知道这个svg基本上可以根据调用页面加载到任何地方?event.clientX为自己提供了屏幕的x坐标.如果我不知道ViewBox的"SecondSVG"的坐标,那么如何在"SecondSVG"的ViewBox中找到x坐标?

我正在使用Firefox 3.6.3并且我有一个事件对象,我可以从中提取clientX,clientY和其他相对于屏幕的坐标.然而,我需要的是ViewBox内的坐标.

Had*_*asi 6

function 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 
}
Run Code Online (Sandbox Code Playgroud)