add lazyload

This commit is contained in:
Harvey Zack committed 2018-10-22 11:10:57 +08:00
1 parent 8b6258c4e5
commit a26afec5ac
4 files changed
+68 -18

No files matched your search

+35 -8
View File
@@ -1054,6 +1054,7 @@
this.art = art;
this.option = option;
this.isLoad = false;
this.init();
}
@@ -1066,14 +1067,44 @@
$progress = _this$art.refs.$progress,
proxy = _this$art.events.proxy;
proxy($progress, 'mousemove', function (event) {
_this.option.ref.style.display = 'block';
_this.checkLoad(_this.art.option.thumbnails.url).then(function () {
_this.option.ref.style.display = 'block';
_this.showThumbnails(event);
_this.showThumbnails(event);
});
});
proxy($progress, 'mouseout', function () {
_this.option.ref.style.display = 'none';
});
}
}, {
key: "checkLoad",
value: function checkLoad(url) {
var _this2 = this;
if (this.isLoad) {
return Promise.resolve(url);
}
var proxy = this.art.events.proxy;
return new Promise(function (resolve, reject) {
var $img = new Image();
$img.src = url;
if ($img.complete) {
_this2.isLoad = true;
resolve(url);
}
proxy($img, 'load', function () {
_this2.isLoad = true;
resolve(url);
});
proxy($img, 'error', function () {
reject(url);
});
});
}
}, {
key: "showThumbnails",
value: function showThumbnails(event) {
@@ -1632,13 +1663,9 @@
}
target.addEventListener(name, callback, option);
var destroy = function destroy() {
this.destroyEvents.push(function () {
target.removeEventListener(name, callback, option);
};
this.destroyEvents.push(destroy);
return destroy;
});
}
}, {
key: "destroy",