简体   繁体   English

svg,得到位置绝对组

[英]svg, get position absolute group

I try to get absolute position of group object. 我试图获得组对象的绝对位置。 In html I have: 在html我有:

<svg width="1301" height="388">
  <g transform="translate(3245.914484377907,2040.9185616875811)scale(1.0)">
    <g class="node" data-toggle="popover" data-placement="bottom" transform="translate(33,50)">
      <image xlink:href="/thumb_glyphicons/commons/stack-overflow.png" x="-3014" y="-1905" width="64" height="64" transform="rotate(0 -2982,-1873)"></image>
      <text x="-2982" y="-1819" text-anchor="middle" font-size="12.8px">absolute position</text>
    </g>
  </g>
</svg>

I see it have some attr: scale, group_main_translate_x, group_main_translate_y, node_translate_x, node_translate_y, node_x, node_y 我看到它有一些attr:scale,group_main_translate_x,group_main_translate_y,node_translate_x,node_translate_y,node_x,node_y

I try function: abs_node_x = (node_translate_x + node_x + group_main_translate_x) * scale. 我尝试函数:abs_node_x =(node_translate_x + node_x + group_main_translate_x)* scale。

It seem be right: (-3014 + 33 + 3245.914484377907) * 1 看起来是对的:(-3014 + 33 + 3245.914484377907)* 1

But when scale != 1, I have wrong value. 但是当比例!= 1时,我的值有误。 Sometime I get "-value" . 有时我得到“ - 值”。

Plz fix the function calculate help me! Plz修复功能计算帮帮我!

abs_position

first, for the question like this let me recommend to use jsFiddle or similar that will show the problem and code. 首先,对于这样的问题,让我建议使用jsFiddle或类似的,以显示问题和代码。

If I understand the question correctly, your function seem to be right. 如果我正确理解了这个问题,那么你的功能似乎是正确的。 All you need to do is divide the result by a zoom value. 您需要做的就是将结果除以缩放值。

Also note that different browsers process scale differently. 另请注意,不同浏览器的处理规模不同。 Chrome might include scale zoom into dimensions whereas IE doesn't. Chrome可能包括尺寸缩放到尺寸,而IE则没有。 So for the box of 200px width scaled by 2x you will get 400px in Chrome and 200px in IE. 因此,对于200x宽度的盒子,缩放2倍,你将获得Chrome浏览器400px和IE浏览器200px。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM