这里真的被卡住了,无法获取SVG矩形计算的样式
我已经创建了一个基于宽度为%的矩形条。如果我调试它,我会看到计算菜单中的像素宽度。我曾尝试在网上寻找解决方案,但没有任何解决方案。
这是我创建的SVG矩形,它是条形图的一部分。
<rect style="fill: white;" id="g2005" x="39px" y="240px" width="44.95%" height="15px" onmouseover="graphMouseIn(id)" onmouseout="graphMouseOut(id)"></rect>
下面的代码,我把XXXXX是我想要魔术插入像素计算宽度的地方。
<animate attributeName="width" from="0" to="XXXXX" dur="0.10s" fill="freeze"></animate>
我曾试图做一些事情来获得它,但它进入未定义或空。
下面的代码给我NULL
<animate attributeName="width" from="0" to=' + ($('#g' + sightingYear).width()) + ' dur="0.10s" fill="freeze" />
下面的代码给我UNDEFINED
<animate attributeName="width" from="0" to=' + (('#g' + sightingYear).width) + ' dur="0.10s" fill="freeze" />
我一直在使用Window.getComputedStyle(),.InnerWidth,都没有工作,也试过。请帮助我,我感谢您的帮助!提前致谢。 :)
你不能叫'getComputedStyle'上SVGElements(其中jQuery的'.WIDTH()'不会调用),你需要'埃尔。 getBoundincClientRect()。width' – Kaiido
@Kaiido'el.getBoundincClientRect()。width'将在'px'中提供宽度。 – ozil
@ ozil,如果我正确地得到问题,那是OP所要的。 – Kaiido