add lazyload

This commit is contained in:
Harvey Zack committed 2018-10-24 16:49:50 +08:00
1 parent 26ce79e459
commit 0235f27ee3
7 files changed
+73 -16

No files matched your search

+34 -2
View File
@@ -1403,6 +1403,8 @@
classCallCheck(this, Thumbnails);
this.option = option;
this.loading = false;
this.isLoad = false;
}
createClass(Thumbnails, [{
@@ -1420,14 +1422,44 @@
$progress = _this$art.refs.$progress,
proxy = _this$art.events.proxy;
proxy($progress, 'mousemove', function (event) {
_this.option.$control.style.display = 'block';
if (!_this.loading) {
_this.loading = true;
_this.showThumbnails(event);
_this.load(_this.art.option.thumbnails.url).then(function () {
_this.isLoad = true;
});
}
if (_this.isLoad) {
_this.option.$control.style.display = 'block';
_this.showThumbnails(event);
}
});
proxy($progress, 'mouseout', function () {
_this.option.$control.style.display = 'none';
});
}
}, {
key: "load",
value: function load(url) {
var proxy = this.art.events.proxy;
return new Promise(function (resolve, reject) {
var image = new Image();
image.src = url;
if (image.complete) {
return resolve(image);
}
proxy(image, 'load', function () {
return resolve(image);
});
proxy(image, 'error', function () {
return reject(image);
});
});
}
}, {
key: "showThumbnails",
value: function showThumbnails(event) {