变更事件名称

This commit is contained in:
Harvey Zack committed 2018-11-21 14:13:37 +08:00
1 parent 4ecdb6b2d9
commit 16586d8d7e
26 files changed
+219 -152

No files matched your search

+23
View File
@@ -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());
}