找到“潜在”隐藏元素的宽度 [英] Find the "potential" width of a hidden element

查看:120
本文介绍了找到“潜在”隐藏元素的宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在扩展 lavalamp插件来处理下拉菜单,但我遇到了一个小问题。我需要知道隐藏的元素的 offsetWidth 。现在明显这个问题没有意义,而是我正在寻找的是 offsetWidth 的元素是不隐藏的。

I'm currently extending the lavalamp plugin to work on dropdown menus but I've encountered a small problem. I need to know the offsetWidth of an element that is hidden. Now clearly this question makes no sense, rather what I'm looking for is the offsetWidth of the element were it not hidden.

解决方案是否显示,抓取宽度,然后再隐藏?必须有一个更好的方法...

Is the solution to show it, grab the width, then hide again? There must be a better way...

推荐答案

我唯一能想到的是显示它它允许检索offsetWidth。

The only thing I can think of is to show it (or a clone of it) to allow retrieval of the offsetWidth.

对于这个测量步骤,只是使它的位置绝对,它的x或y值是一个大负数,所以它会渲染,但不是对用户可见。

For this measurement step, just make its position absolute and its x or y value a big negative, so it will render but not be visible to the user.

这篇关于找到“潜在”隐藏元素的宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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