mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-13 15:56:15 -08:00
添加自动隐藏光标
This commit is contained in:
1 parent
617fd9681e
commit
d9fd20bdf3
14 files changed
+127
-27
No files matched your search
@@ -24,6 +24,7 @@ export default class FullscreenWeb {
|
||||
tooltip(this.$fullscreenWeb, i18n.get('Exit web fullscreen'));
|
||||
}
|
||||
player.resetAspectRatio();
|
||||
art.emit('fullscreenWeb', this.state);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ export default class Screenshot {
|
||||
proxy(this.$screenshot, 'click', () => {
|
||||
try {
|
||||
this.captureFrame();
|
||||
art.emit('screenshot');
|
||||
} catch (error) {
|
||||
notice.show(error);
|
||||
}
|
||||
|
||||
@@ -15,10 +15,12 @@ export default class Setting {
|
||||
setting.hide();
|
||||
setStyle(this.$setting, 'opacity', '1');
|
||||
tooltip(this.$setting, i18n.get('Show setting'));
|
||||
art.emit('setting:hide');
|
||||
} else {
|
||||
setting.show();
|
||||
setStyle(this.$setting, 'opacity', '0.8');
|
||||
tooltip(this.$setting, i18n.get('Hide setting'));
|
||||
art.emit('setting:show');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -15,10 +15,12 @@ export default class Subtitle {
|
||||
subtitle.hide();
|
||||
setStyle(this.$subtitle, 'opacity', '1');
|
||||
tooltip(this.$subtitle, i18n.get('Show subtitle'));
|
||||
art.emit('subtitle:hide');
|
||||
} else {
|
||||
subtitle.show();
|
||||
setStyle(this.$subtitle, 'opacity', '0.8');
|
||||
tooltip(this.$subtitle, i18n.get('Hide subtitle'));
|
||||
art.emit('subtitle:show');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -56,8 +56,6 @@ export default function aspectRatioMix(art, player) {
|
||||
value: () => {
|
||||
const { refs: { $player } } = art;
|
||||
const { aspectRatio } = $player.dataset;
|
||||
console.log($player.dataset);
|
||||
console.log(aspectRatio);
|
||||
if (aspectRatio) {
|
||||
player.aspectRatio(aspectRatio.split(':'));
|
||||
}
|
||||
|
||||
@@ -2,17 +2,9 @@ import config from '../config';
|
||||
import { sleep } from '../utils';
|
||||
|
||||
export default function eventInit(art, player) {
|
||||
const { option, events: { proxy, hover }, refs: { $player, $video }, i18n, notice } = art;
|
||||
const { option, events: { proxy }, refs: { $player, $video }, i18n, notice } = art;
|
||||
let firstCanplay = false;
|
||||
|
||||
hover($player, () => {
|
||||
$player.classList.add('artplayer-hover');
|
||||
art.emit('hoverenter');
|
||||
}, () => {
|
||||
$player.classList.remove('artplayer-hover');
|
||||
art.emit('hoverleave');
|
||||
});
|
||||
|
||||
proxy($video, 'click', () => {
|
||||
player.toggle();
|
||||
});
|
||||
|
||||
@@ -22,4 +22,14 @@ export default function playbackRateMix(art, player) {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Object.defineProperty(player, 'resetPlaybackRate', {
|
||||
value: () => {
|
||||
const { refs: { $player } } = art;
|
||||
const { playbackRate } = $player.dataset;
|
||||
if (playbackRate) {
|
||||
player.playbackRate(Number(playbackRate));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
.artplayer-video-player {
|
||||
&.artplayer-hide-cursor {
|
||||
* {
|
||||
cursor: none !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,5 +10,6 @@ import './notice.scss';
|
||||
import './contextmenu.scss';
|
||||
import './setting.scss';
|
||||
import './info.scss';
|
||||
import './hideCursor.scss';
|
||||
import './aspectRatio.scss';
|
||||
import './fullscreenWeb.scss';
|
||||
@@ -115,3 +115,17 @@ export function sleep(ms = 0) {
|
||||
export function sublings(target) {
|
||||
return Array.from(target.parentElement.children).filter(item => item !== target);
|
||||
}
|
||||
|
||||
export function debounce(func, wait, scope) {
|
||||
let timeout;
|
||||
return function fn() {
|
||||
const context = scope || this;
|
||||
const args = arguments;
|
||||
const later = function later() {
|
||||
timeout = null;
|
||||
func.apply(context, args);
|
||||
};
|
||||
clearTimeout(timeout);
|
||||
timeout = setTimeout(later, wait);
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user