Find the “potential” width of a hidden element

前端 未结 10 1347
慢半拍i
慢半拍i 2020-12-03 09:31

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

10条回答
  •  我在风中等你
    2020-12-03 10:25

    Two options:

    1. position the element outside the viewport (ex: left:-10000px)
    2. use visibility: hidden or opacity: 0 instead of hide().

    Either way will work as hiding the element but still being able to get the computed width. Be careful with Safari on thi, it's awfully fast and sometimes too fast...

提交回复
热议问题