JQuery Mozilla Firefox svg.height () error?

$('svg').height()

      

Just stumbled upon an interesting error (?) That appears in Mozilla when trying to get the height of the svg. While you are trying to set the SVG SVC container size in percentage, jQuery svg.height () will not return a pixel value, but a percentage.

Chrome works fine. Just open this script in Mozilla Firefox and Chrome and compare the results: http://jsfiddle.net/Ltew9pjb/3/

The answer to this question is simple, if SVG uses display: none, Mozilla Firefox will return a percentage value for some reason, and when there is no display: none, Mozilla will return a px value. I don't know if this is really a bug or not, but now how does it work. Check out this fiddle: http://jsfiddle.net/Ltew9pjb/4/

So, I want to ask if this is really a Mozilla Firefox or jQuery bug or something else?

+3


source to share


1 answer


according to jQuery docs

The value specified as .hight () is not guaranteed if it is an element or its parent is hidden . To get the exact value, the element is seen before using .height (). jQuery will try to temporarily show and then hide the element again to measure its dimensions, but this is unreliable and (even when accurate) can significantly impact page performance. This show-and-rehide measurement function may be removed in a future version of jQuery.



So this is not the fault of either of them.

+2


source







All Articles