【发布时间】:2014-05-06 13:13:50
【问题描述】:
对于 Firefox 和 Safari 中的 svg:text tspan 元素,宽度似乎总是为零(或 null)。
jQuery 函数 width() 和 height() 在 Firefox 11 和 IE 9 中为 SVG tspan 文本元素返回 0。 在 Chrome 17 和 19 中,它们都按预期工作。 我也试过 usinf offsetWidth 和 getComputedTextLength() 都返回 0 或 null。
这是我的查询代码:
$('svg #aitext-2-front-middle').find('tspan').each(function(i){
var currWidth = $(this).width();
console.log(currWidth);
});
这是 svg 部分:
<text id="aitext-2-front-middle" transform="matrix(1 0 0 1 81.7744 155.248)">
<tspan x="66.287" y="57.6" font-family="'MyriadPro-Regular'" font-size="12">lightweight UIs using </tspan>
<tspan x="39.72" y="72" font-family="'MyriadPro-Regular'" font-size="12">Adobe Illustrator CS5 (or above) </tspan>
<tspan x="40.146" y="86.4" font-family="'MyriadPro-Regular'" font-size="12">along with some free resources. </tspan>
<tspan x="79.385" y="100.8" font-family="'MyriadPro-Regular'" font-size="12">Let’s get started.</tspan>
</text>
【问题讨论】:
-
你在哪个平台上?我在 chrome 34 上写这个文本...
-
感谢您的评论..是的,我使用的是 chrome 34.. 但是 chrome 运行良好,但我在使用 Firefox 和 safari 时遇到问题
标签: javascript jquery svg