Convert css width string to regular number

后端 未结 5 828
闹比i
闹比i 2020-12-15 18:11

While trying to compute the width of an hidden element I found that jquery.width() returns 0 for that elements\' width.

I found out that using jquery.css(\'width\'

5条回答
  •  被撕碎了的回忆
    2020-12-15 18:19

    I would stick to .width() because it actually gets the computed width instead of css width. Instead of hiding it with .hide() (display: none) you could hide it with .css('visible', 'hidden') then .width() should work.

    from my comment If you don't want to change your .hide()´s then you could apply visible: hidden and thereafter .show() and then measure the height. After you have measured it, reverse that. Objects still affects the page layout when they are hidden by visible: hidden - beware of that.

    To avoid tags which mess with the layout, you could set the position to absolute, move it to the body tag and then measure.

提交回复
热议问题