简体   繁体   English

无需渲染即可测量 SVG 文本尺寸

[英]Measure SVG text dimensions without rendering

I would like to calculate a text's width before rendering it (for the purpose of laying out the texts).我想在渲染之前计算文本的宽度(为了布置文本)。 Using getBBox() works on Chrome browsers but breaks using Firefox ( NS_ERROR ).使用getBBox()适用于 Chrome 浏览器,但使用 Firefox ( NS_ERROR ) 会中断。

What is the suggested way to calculate SVG text dimensions without rendering it?在不渲染的情况下计算 SVG 文本尺寸的建议方法是什么?

You probably used the style display: none .您可能使用了样式display: none Try visibility: hidden instead and .getBBox() should work.尝试visibility: hidden而不是.getBBox()应该工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM