在Internet Explorer中确定SVG大小的正确方法是什么?

时间:2013-09-28 21:15:17

标签: internet-explorer svg

正如标题所说:确定Internet Explorer中SVG元素大小(宽度,高度)的正确方法是什么?

大多数浏览器似乎支持.offsetWidth.offsetHeight,但这似乎不适用于IE(使用IE 10测试)。

小提琴:http://jsfiddle.net/c7eqe/1/(在IE上,显示“offsetWidth:undefined”)

1 个答案:

答案 0 :(得分:0)

经过一些实验,似乎所有主流浏览器都支持getBoundingClientRect()({1}}:https://developer.mozilla.org/en-US/docs/Web/API/element.getBoundingClientRect

>> svg = document.getElementsByTagName("svg")[0]
>> svg.getBoundingClientRect()
[object ClientRect] {
    bottom : 590,
    height : 400,
    left : 199,
    right : 1009,
    top : 190,
    width : 810
>>
相关问题