Can't get right width or outerWidth of

2019-08-05 19:05发布

simply can not understand this problem I have - I need the .outerWidth() of a <label> element, but it keeps returning a value that is different from the one I can read out of my firebug?

.outerHeight works just fine though.

SOLVED: Note to self: custom fonts and calculations of width does not work all that well, lol

3条回答
放我归山
2楼-- · 2019-08-05 19:37

SOLUTION/PROBLEM: I used custom fonts - must be a workaround though - dont have time to find it yet :-D

查看更多
啃猪蹄的小仙女
3楼-- · 2019-08-05 19:45

When you use custom fonts, you must use the .outerHeight method on $(window).load(function(){}, not $(document).ready(function(){}. The first case waits for all the elements of the window to be loaded (including the custom font and the image) otherwise in the second case it is ready before the custom element is loaded and it not know the dimension of it.

查看更多
何必那么认真
4楼-- · 2019-08-05 19:45

Maybe you need .outerWidth(true) wich includes the margin of the element.

http://api.jquery.com/outerWidth/ for more specific information on the outerWidth function.

查看更多
登录 后发表回答