JQuery simple implementation of image pre-loading _ jquery

Source: Internet
Author: User
During website creation, we often encounter the following problem: a large number of images on a page causes slow page loading speed, and a white page user experience is often poor. How can this problem be solved? Next I will introduce a js pre-loading method that is often used in practical applications. Implement image pre-loading using jQuery

JS Code

$(function(){   loadImg("http://d.hiphotos.baidu.com/image/pic/item/fd039245d688d43f14f69eff7f1ed21b0ef43b5b.jpg",addImg);  function loadImg(url,callback){    var img = new Image();    img.onload = function(){      img.onload = null;      callback(img);    }    img.src=url;    img.width ="202";    img.height = "202";    img.attr("defaulturl","../images/img.png");    if(){}  }  function addImg(img){    $(img).appendTo($(".imgload li"))  }})


   Image pre-loading  
Related Article

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.