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:
you set elements opacity 0. way won't displayed end user while getting dimensions.
you set element position "absolute". way won't take space.
now it's safe set display "inline-block".
you read elements dimensions. time you'll real values.
you set display "hidden" , set opacity , position original values.
and have size of hidden element.
Comments
Post a Comment