Svg getComputedTextLength函数总是返回零 [英] Svg getComputedTextLength function always returning zero

查看:1116
本文介绍了Svg getComputedTextLength函数总是返回零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我试图从

http://mbostock.github.io/d3/talk/20111018/treemap.html

getComputedTextLength()总是返回0.我也尝试了 getBBox(),但它返回一个对象的所有属性为零。

but the getComputedTextLength() always returns 0. I also tried getBBox(), but it returns an object with all properties with zero.

    .text(function(d) { return d.name; })
    .style("opacity", function(d) {
         d.w = this.getComputedTextLength(); 
         return d.dx > d.w ? 1 : 0;
    });

我需要把我的文本包裹在 tspan

还有什么其他原因可以产生这个?

Do I need to put my text wrapped in a tspan?
What other reasons could generate this?

推荐答案

年末,但我最近碰到了同样的问题,这可能有助于某人。 如果 text 元素尚未呈现,或者如果容器或任何其他任何元素,则 c> this.getComputedTextLength其父容器在文本时将显示设置为 none c>元素。

I realize that this is over a year late, but I ran into the same issue recently and this may help someone. this.getComputedTextLength() returns 0 if the text element hasn't been rendered yet or if the container or any of its parent containers have display set to none at the time the text element is being rendered.

这篇关于Svg getComputedTextLength函数总是返回零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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