添加自动隐藏光标

This commit is contained in:
Harvey Zack committed 2018-11-05 15:35:09 +08:00
1 parent 617fd9681e
commit d9fd20bdf3
14 files changed
+127 -27

No files matched your search

+24
View File
@@ -1,14 +1,38 @@
import { debounce } from './utils';
export default class Events {
constructor(art) {
this.art = art;
this.destroyEvents = [];
this.proxy = this.proxy.bind(this);
this.hover = this.hover.bind(this);
this.init();
}
init() {
const { refs: { $player } } = this.art;
this.hover($player, () => {
$player.classList.add('artplayer-hover');
this.art.emit('hoverenter');
}, () => {
$player.classList.remove('artplayer-hover');
$player.classList.remove('artplayer-hide-cursor');
this.art.emit('hoverleave');
});
const hideCursor = debounce(() => {
$player.classList.add('artplayer-hide-cursor');
}, 5000);
this.proxy($player, 'mousemove', () => {
$player.classList.remove('artplayer-hide-cursor');
hideCursor();
});
}
proxy(target, name, callback, option = {}) {
if (Array.isArray(name)) {
name.forEach(item => this.proxy(target, item, callback, option));
return;
}
target.addEventListener(name, callback, option);