jQuery Mozilla Firefox svg.height() 错误?
jQuery Mozilla Firefox svg.height() bug?
$('svg').height()
刚刚偶然发现了一个有趣的错误 (?),它在试图获取 svg 高度时出现在 Mozilla 中。当您尝试通过 css 以百分比设置 SVG 容器大小时,jQuery svg.height() 将 return 不是像素值,而是百分比值。
Chrome 工作正常。只需在 Mozilla Firefox 和 Chrome 中打开此 fiddle 并比较结果:http://jsfiddle.net/Ltew9pjb/3/
现在的答案很简单,如果 SVG 使用 display:none,Mozilla Firefox 出于某种原因将 return 百分比值,并且当没有显示时:none,Mozilla将 return px 值。我不知道它是否真的是一个错误,但现在它是这样工作的。检查此 fiddle:http://jsfiddle.net/Ltew9pjb/4/
所以我想问一下它是真正的 Mozilla Firefox 还是 jQuery 错误,还是其他什么?
The value reported by .height() is not guaranteed to be accurate when
the element or its parent is hidden. To get an accurate value, ensure
the element is visible before using .height(). jQuery will attempt to
temporarily show and then re-hide an element in order to measure its
dimensions, but this is unreliable and (even when accurate) can
significantly impact page performance. This show-and-rehide
measurement feature may be removed in a future version of jQuery.
所以这不是它们中任何一个的错误。
$('svg').height()
刚刚偶然发现了一个有趣的错误 (?),它在试图获取 svg 高度时出现在 Mozilla 中。当您尝试通过 css 以百分比设置 SVG 容器大小时,jQuery svg.height() 将 return 不是像素值,而是百分比值。
Chrome 工作正常。只需在 Mozilla Firefox 和 Chrome 中打开此 fiddle 并比较结果:http://jsfiddle.net/Ltew9pjb/3/
现在的答案很简单,如果 SVG 使用 display:none,Mozilla Firefox 出于某种原因将 return 百分比值,并且当没有显示时:none,Mozilla将 return px 值。我不知道它是否真的是一个错误,但现在它是这样工作的。检查此 fiddle:http://jsfiddle.net/Ltew9pjb/4/
所以我想问一下它是真正的 Mozilla Firefox 还是 jQuery 错误,还是其他什么?
The value reported by .height() is not guaranteed to be accurate when the element or its parent is hidden. To get an accurate value, ensure the element is visible before using .height(). jQuery will attempt to temporarily show and then re-hide an element in order to measure its dimensions, but this is unreliable and (even when accurate) can significantly impact page performance. This show-and-rehide measurement feature may be removed in a future version of jQuery.
所以这不是它们中任何一个的错误。