/******** 代理类实现每张图片的loading ********/
function Img() {
this.img = document.createElement('img')
document.body.appendChild(this.img)
}
Img.prototype.setSrc = function (src) {
this.img.src = src
}
//代理函数
function ProxyImg(src) {
this.img = new Img()
this.img.setSrc('./loading.png') //先设置loading图片
let image = new Image();
image.src = src;
let self = this;
//图片加载完毕后 ----> 再显示真正的图片
image.onload = function () {
self.img.setSrc(src)
}
}
new ProxyImg('./1.png')
new ProxyImg('./2.png')
new ProxyImg('./3.png')
new ProxyImg('./4.png')
new ProxyImg('./5.png')