在不渲染的情况下测量SVG文本尺寸 [英] Measure SVG text dimensions without rendering

查看:107
本文介绍了在不渲染的情况下测量SVG文本尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在渲染之前计算文本的宽度(以布置文本为目的).在Chrome浏览器上使用getBBox()可以使用,但在Firefox(NS_ERROR)上可以使用.

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).

在不渲染SVG文本尺寸的情况下,建议的方法是什么?

What is the suggested way to calculate SVG text dimensions without rendering it?

推荐答案

您可能使用了display: none样式.尝试使用visibility: hidden代替,并且.getBBox()应该可以工作.

You probably used the style display: none. Try visibility: hidden instead and .getBBox() should work.

这篇关于在不渲染的情况下测量SVG文本尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆