jquery .load() doesn't work after hard refresh

后端 未结 5 1697
梦如初夏
梦如初夏 2021-01-16 19:03

I have some code that when the page loads gets the height of an image and then resizes its container div accordingly. This works fine unless its the first time the page has

5条回答
  •  不思量自难忘°
    2021-01-16 19:17

    If your images do not have width/height specified in HTML or CSS, then their width/height is not known until after the images have been downloaded.

    $(document).ready fires when the DOM has been loaded, but potentially before auxiliary media such as images have been downloaded. That means you have a width/height, potentially, of 0 when your browser is re-downloading the images.

    Maybe you can use something like this. The "imagesLoaded" plugin in particular looks useful (though its code implies that $(imgs).load should have worked for you >.<).

提交回复
热议问题