$(document).ready() fires too early

前端 未结 7 1636
青春惊慌失措
青春惊慌失措 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:15

    The "ready" event fires when the DOM is loaded which means when it is possible to safely work with the markup.

    To wait for all assets to be loaded (css, images, external javascript...), you'd rather use the load event.

    $(window).load(function() {
        ...
    });
    

提交回复
热议问题