- $(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"))
- }
- })
- <!doctype html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>图片预加载</title>
- <link rel="stylesheet" type="text/CSS" >
- <script type="text/javascript" src1="js/jquery-1.8.3.min.js"></script>
- <script type="text/javascript" src1="js/index.js"></script>
- </head>
- <body>
- <div class="imgload">
- <ul>
- <li class="fl"></li>
- <li class="fl"></li>
- <li class="fl"></li>
- <li class="fl"></li>
- <li class="fl"></li>
- <li class="fl"></li>
- <li class="fl"></li>
- <li class="fl"></li>
- <li class="fl"></li>
- </ul>
- </div>
- </body>
- </html>
- //该片段来自于http://www.codesnippet.cn/detail/2104201512345.html
来源: http://www.codesnippet.cn/detail/2104201512345.html