How to get the height of a hidden image?

前端 未结 5 2023
陌清茗
陌清茗 2021-01-20 05:29

When a div is hidden (display:none) the browser will not load the images that are inside it. Is there a way to tell the browser to load the image?

5条回答
  •  难免孤独
    2021-01-20 06:26

    Make the div visible, but position it outside the page with position: absolute;.

    If your "other code" doesn't let you do this either, create a new image node with the same URL, position it outside the page, wait until it's loaded, read its height and destroy.

提交回复
热议问题