javascript - How to obtain clientWidth & clientHeight before DIV is visible -


i want obtain dimensions of div element (used display popup menu @ cursor position) while it's style.display='none;', dimensions of div return 0. way seem able dimensions make div style.display='block;' @ 0,0 , move required position, looks jumpy.

i've tried making div visible outside of visible screen area doesn't work. there way clientwidth , clientheight values whilst div hidden?

if div not visible, won't able dimensions.

however, there workaround. div has "visible", doesn't mean it's opacity , position have 1 , relative.

set opacity 0 , position "absolute" , you'll able div dimensions.


edit

since think more people have similar problem, feel should explain answer little more.

if try size of hidden element javascript, 0.

so there techniques real size without displaying element user. favourite 1 wrote above. here more detailed steps:

  1. you set elements opacity 0. way won't displayed end user while getting dimensions.

  2. you set element position "absolute". way won't take space.

  3. now it's safe set display "inline-block".

  4. you read elements dimensions. time you'll real values.

  5. you set display "hidden" , set opacity , position original values.

and have size of hidden element.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -