Home  >  Article  >  Web Front-end  >  Implementation and usage of unordered preloading of images in jquery

Implementation and usage of unordered preloading of images in jquery

不言
不言Original
2018-08-13 10:40:151388browse

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(num

How 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn