Image pre-loading, On-Demand Loading

Source: Internet
Author: User

We often encounter such situations.

1. During page layout, some images are packaged with the IMG label and some are background-image. When the user's network is fast, you will obviously find that the image of the IMG tag will be loaded first, and then the image of the background-image will be loaded at the end. At this time, you will find that the page user experience is very poor, the background-image does not render the interface, which is a bit ugly.

2. We hope that the images will be loaded in a pre-arranged order.

3. When will images be loaded?

Javascript can be used as follows:

For example, pre-load the background image:

Function LoadImage (URL) {var IMG = new image (); IMG. src = URL;} var bg_imgs = new array ("/images/home/bottom_bg.png", "/images/home/bottom_bg2.png", "/images/home/bottom_bg3.png ", "/images/SUB/mid_bg.jpg", "/images/SUB/mid_bg2.jpg", "/images/SUB/mid_bg3.jpg"); For (VAR I = 0; I <bg_imgs.length; I ++) {LoadImage (bg_imgs [I]);}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.