Home > Article > Web Front-end > Implementation and usage of unordered preloading of images in jquery
The content of this article is about the implementation and usage of unordered image preloading in jquery. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
/图片无序预加载 (function($){ function Preload(imgs,fns){ this.imgs=(typeof imgs==="string")?[imgs]:imgs; this.fns=$.extend({},Preload.fns,fns);//把fns 覆盖到Preload上 然后添加到{}返回 if(this.fns.loadMethod=="unorderload"){//是无序 还是有序 this._unorderload(); } else{ this._orderload(); } } Preload.fns={ loadMethod:null,//有序还是无序的方式 eachLoadImg:null, //每张图片加载完所执行的函数 allLoadImg:null //所有图片加载完所要执行的函数 } Preload.prototype._orderload=function(){ var imgs=this.imgs, len=imgs.length, fns=this.fns, num=0; function load(){ var imgObj=new Image(); $(imgObj).on("load error",function(){ fns.each && fns.each(); //存在 才会执行 if(numHow to use
有序预加载 ![]()
Related recommendations:
The difference and conversion between jQuery objects and native DOM objects
What is a js object? What are the js object types? Summary of js object types
The above is the detailed content of Implementation and usage of unordered preloading of images in jquery. For more information, please follow other related articles on the PHP Chinese website!