$(document).ready() fires too early

前端 未结 7 1617
青春惊慌失措
青春惊慌失措 2020-12-30 19:29

So, I need to know the width of an element with javascript, the problem I have is that the function fires too early and the width changes when the css is tottally applied. A

7条回答
  •  春和景丽
    2020-12-30 20:11

    The jQuery .ready() function fires as soon as the DOM is complete. That doesn't mean that all assets (like images, CSS etc) have been loaded at that moment and hence the size of elements are subject to change.

    Use $(window).load() if you need the size of an element.

提交回复
热议问题