开发者

Does setting of width and height only work in jquery if the element is visible?

开发者 https://www.devze.com 2023-03-18 04:54 出处:网络
Does setting of width and height only work in jquery if t开发者_开发百科he element is visible?

Does setting of width and height only work in jquery if t开发者_开发百科he element is visible? Unless I do show - nothing gets resized, however this is causing flickering. Is there a way to make it work even when the element I want to resize or its container is not visible?


No, setting the height/width sets attributes directly no matter what the old value was, it doesn't matter if it's visible or not.
Getting the height and width might be a different story.

How do you know it doesn't get resized if it's hidden? How are you hiding the elements?


I've tried resizing a div when having visibility:hidden; on it and it works: http://jsfiddle.net/RUThh/

And here with display:none;: http://jsfiddle.net/PAvzn/


I had a similar problem a while ago. What I did to fix it was use jQuery to temporarily give it a position:absolute, then I "showed" it at -9999px which triggered the browser rendering the element and thus giving it dimensions, read those dimensions, then put it back and made it invisible again.

0

精彩评论

暂无评论...
验证码 换一张
取 消