Preload image in index.html to use on another page

孤人 提交于 2019-12-11 10:32:41

问题


I have a large image that displays as a background on another page of my website. I want to preload this image when users first go to my webpage so that when they eventually move to the page with the image on it, it loads instantly.

I use this to preload:

<script type="text/javascript">
  if (document.images) {
  img1 = new Image();
  img1.src = "image.jpg";
}
</script>

How do I use this so it stores the image to use on a later page?

Thanks in advance!


回答1:


ANSWER:

Turns out if I simply put the above js at the bottom of my index.html, it loads the image into the cache and then the browser will grab that image when the user clicks to go to another page that includes the image.

In other words, I already had the answer!




回答2:


I think what you are looking for is image pre-Loading.

Have a look here

Hope this helps


来源:https://stackoverflow.com/questions/17870875/preload-image-in-index-html-to-use-on-another-page

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!