鞋子:Element.width 返回0
我不明白为什么如果宽度函数对于非零宽度元素返回 0,那么它会在所有元素上实现。 以下对我来说返回 0。
Shoes.app do
p = para "My width is: "
para p.width
end
这是为什么? (app.width不返回0)
I don't understand why the width function is implemented on all elements if it returns 0 for non-zero width elements. The following returns 0 for me.
Shoes.app do
p = para "My width is: "
para p.width
end
Why is that? (app.width does not return 0)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题在于,para 对象的大小是在绘制时动态确定的。 在创建第二个段落时,实际上尚未布局任何内容,因此尚未设置宽度。 您可以看到,绘制后访问宽度按预期工作:
解决此问题的方法是使用 start 方法,该方法在第一次绘制包含槽时调用:
The problem is that the size of the para object is determined dynamically when it is drawn. At the time you create the second para, nothing has actually been laid out yet, so a width hasn't been set. You can see that accessing the width after drawing works as expected:
The way to get around this is to use the start method, which is called when the containing slot is drawn for the first time: