How to get SVG element dimensions in FireFox?

前端 未结 4 1081
轮回少年
轮回少年 2020-12-10 01:49

In most browsers, the following would work.

window.onload = function(){
    console.log( document.getElementById(\'svgElm\').getBoundingClientRect().width );         


        
4条回答
  •  鱼传尺愫
    2020-12-10 02:29

    I've ended up falling back to the parent dimensions if SVG properties cannot be returned. Here is a demo http://jsbin.com/uzoyik/1/edit.

    The relavent code is:

    svg.clientWidth || svg.parentNode.clientWidth
    svg.clientHeight || svg.parentNode.clientHeight
    

提交回复
热议问题