mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-26 17:01:20 -08:00
变更事件名称
This commit is contained in:
1 parent
4ecdb6b2d9
commit
16586d8d7e
26 files changed
+219
-152
No files matched your search
@@ -9,6 +9,7 @@ export default class Events {
|
||||
this.destroyEvents = [];
|
||||
this.proxy = this.proxy.bind(this);
|
||||
this.hover = this.hover.bind(this);
|
||||
this.loadImg = this.loadImg.bind(this);
|
||||
clickInit(art, this);
|
||||
hoverInit(art, this);
|
||||
mousemoveInit(art, this);
|
||||
@@ -33,6 +34,28 @@ export default class Events {
|
||||
this.proxy(target, 'mouseleave', mouseleave);
|
||||
}
|
||||
|
||||
loadImg(img) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let image;
|
||||
|
||||
if (img instanceof HTMLImageElement) {
|
||||
image = img;
|
||||
} else if (typeof img === 'string') {
|
||||
image = new Image();
|
||||
image.src = img;
|
||||
} else {
|
||||
return reject(img);
|
||||
}
|
||||
|
||||
if (image.complete) {
|
||||
return resolve(image);
|
||||
}
|
||||
|
||||
this.proxy(image, 'load', () => resolve(image));
|
||||
this.proxy(image, 'error', () => reject(image));
|
||||
});
|
||||
}
|
||||
|
||||
destroy() {
|
||||
this.destroyEvents.forEach(event => event());
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user