How to Preload Images without Javascript?

后端 未结 9 1332
有刺的猬
有刺的猬 2020-12-01 02:48

In one of My Layout there are some large images (come from XML) which shown when I mouse hover on some some of the link, but when the Page loads and when i rollover It takes

相关标签:
9条回答
  • 2020-12-01 03:32

    Reference your images in invisible img tags. while page loading they will downloaded too.

    0 讨论(0)
  • 2020-12-01 03:37

    Can't you add them as an <img /> tag to your page and hide them using css?

    0 讨论(0)
  • 2020-12-01 03:39

    If preloading images is what you seek, then performance is what you want. I doubt blocking up the page while the resources load is what you want. SO, just place some prefetching links at the end of the body and add the bogus media to them to make them appear unimportant (so that they get loaded after everything else). Then, add the onload tag to those links, and in that onload will be the code that sets the source of the actual resource in your page. For example, this could even be used in conjunction with dynamic iframes.

    Before:

    <a onclick="myFrame.style.opacity=1-myFrame.style.opacity;myFrame.src='http://jquery.com/'">
        Click here to toggle it
    </a><br />
    <iframe id="myFrame" src="" style="opacity: 0"></iframe>

    After:

    <a onclick="myFrame.style.opacity=1-myFrame.style.opacity">
        Click here to toggle it
    </a><br />
    <iframe id="myFrame" src="" style="opacity: 0"></iframe>
    <link rel="prefetch" href="http://jquery.com/"
          onload="myFrame.src=this.href" media="bogus" />

    Notice how the first one (before) freezes up the page and blinks in a quite ugly manner while the second one (after) with the content preloaded doesn't freeze up the page or blink, rather it appears and disappears seamlessly instantly.

    0 讨论(0)
提交回复
热议问题