附加到DOM之前的DOM元素宽度 [英] DOM Element Width before Appended to DOM

查看:72
本文介绍了附加到DOM之前的DOM元素宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我确定答案是否定的,但是可以在之前确定元素的宽度是否被附加到DOM?



谢谢

解决方案

诀窍是显示元素(display:block),但也隐藏它(visibility:hidden)并将其位置设置为绝对位置,以便它不会影响页面流。



MooTools Element.Measure类可以做到这一点,就像奥斯卡提到的一样。


I'm sure the answer is no, but is it possible to determine the width of an element before it is appended to the DOM?

Once it's appended, I know I can use offsetWidth and offsetHeight.

Thanks

解决方案

The trick is to show the element (display:block) but also hide it (visibility:hidden) and to set it’s position to absolute so that it doesn’t affect the page flow.

The MooTools Element.Measure class does this, as Oscar mentioned.

这篇关于附加到DOM之前的DOM元素宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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