簡體   English   中英

SVG-獲取TextElement的字體大小

[英]SVG - Get font-size of a TextElement

當可以由CSS設置和/或繼承時,如何獲取SvgTextElement的字體大小?

僅當元素具有直接應用的屬性時,“ getAttributeNS”才有效。 我認為可能需要'baseVal',但我沒有運氣。

瀏覽器:IE + Adob​​e Svg Viewer Firefox Chrome IE9

var fontSize = window.getComputedStyle(element, null).getPropertyValue("font-size");

其中element是document.getElementById或類似結果的結果。

這實際上是評論的性質。 以下是一些較簡單的公式:

var fontSize = window.getComputedStyle(element).fontSize;

如果您希望能夠搜索短語“ font-size”,則可以使用以下功能:

var fontSize = window.getComputedStyle(element)['font-size'];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM