图片预加载的插件使用-jquery.imgpreload.min.js

使用方法:

 1 //图片预加载
 2 var the_images = [];//新建一个数组,然后将要加载的图片地址推入这个数组中;
 3 the_images.push( 'bg.jpg' );
 4 var loading_process = 0;
 5 jQuery.imgpreload(the_images,//开始运行预加载;
 6     {
 7         each: function()//each的意思是,每次加载完一个图片后,执行此匿名函数中的代码,本例仅仅是将图片的地址打印到页面而已,所以大家不用纠结“为什么没有看到图片”
 8         {
 9             var status = $(this).data('loaded')?'success':'error';
10             loading_process += Math.round(100/(the_images.length));
11             if(loading_process<100){
12                 $('p').html(loading_process+'%');
13             }
14         },
15         all: function()//all的意思是,当所有图片加载完毕之后,执行此函数体内的内容;举个例子,如果有5张图片需要预加载,则each中的function会执行5次,而all的function 只会执行一次~
16         {
17            
18          }
19     }
);
原文地址:https://www.cnblogs.com/winteronlyme/p/7639659.html