Why does jQuery's height() automatically rounds up the value?

前端 未结 1 2004
予麋鹿
予麋鹿 2021-01-22 21:29

I wanted to calculate the computed height of a list. On IE, these two give different results. On Chrome, the value seems to be always on integer, so I do not get this problem.

相关标签:
1条回答
  • 2021-01-22 21:42

    This is a known bug in jQuery, which shouldn't round height and width values.

    http://bugs.jquery.com/ticket/9628

    Updated with @CookieMonster's comment

    The current workaround is to use .getBoundingClientRect().height, which is cross browser and doesn't round values.

    document.getElementById("fruits").getBoundingClientRect().height
    
    0 讨论(0)
提交回复
热议问题