Recently a project Home picture too much, they search the Internet to find information on the solution, we collected some methods, and encapsulation.
The easiest way is to picture the src value in an array, the array is traversed by a for loop, create images and objects added to the picture src attribute of an object traversing the src value, after writing a callback function in onload you can use a picture of the object. demo code is as follows:
|
|
用法:
- 引入jquery库和以上代码
- $.progress(imgs, opts)
- 具体看实例github
鸣谢
原文:大专栏 封装了个图片预加载 · KYLE'S BLOG