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

+29 -2
View File
@@ -1,6 +1,8 @@
export default class Thumbnails {
constructor(option) {
this.option = option;
this.loading = false;
this.isLoad = false;
}
apply(art) {
@@ -15,8 +17,17 @@ export default class Thumbnails {
} = this.art;
proxy($progress, 'mousemove', event => {
this.option.$control.style.display = 'block';
this.showThumbnails(event);
if (!this.loading) {
this.loading = true;
this.load(this.art.option.thumbnails.url).then(() => {
this.isLoad = true;
});
}
if (this.isLoad) {
this.option.$control.style.display = 'block';
this.showThumbnails(event);
}
});
proxy($progress, 'mouseout', () => {
@@ -24,6 +35,22 @@ export default class Thumbnails {
});
}
load(url) {
const { proxy } = this.art.events;
return new Promise((resolve, reject) => {
const image = new Image();
image.src = url;
if (image.complete) {
return resolve(image);
}
proxy(image, 'load', () => resolve(image));
proxy(image, 'error', () => reject(image));
});
}
showThumbnails(event) {
const { $progress } = this.art.refs;
const { width: posWidth } = this.getPosFromEvent(event);
-8
View File
@@ -1,5 +1,3 @@
@charset "UTF-8";
.artplayer-video-player {
position: relative;
width: 100%;
@@ -27,10 +25,4 @@
fill: #fff;
}
}
&.artplayer-error {
.art-progress-indicator, .art-progress-tip {
display: none !important;
}
}
}
+6
View File
@@ -204,4 +204,10 @@
visibility: visible;
}
}
&.artplayer-error {
.art-progress-indicator, .art-progress-tip {
display: none !important;
}
}
}