mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-27 01:21:20 -08:00
add autoMin
This commit is contained in:
1 parent
33a7e1193d
commit
b202c21a7f
11 files changed
+150
-18
No files matched your search
@@ -3,6 +3,7 @@ import hoverInit from './hoverInit';
|
||||
import mousemoveInit from './mousemoveInit';
|
||||
import resizeInit from './resizeInit';
|
||||
import gestureInit from './gestureInit';
|
||||
import viewInit from './viewInit';
|
||||
|
||||
export default class Events {
|
||||
constructor(art) {
|
||||
@@ -18,13 +19,14 @@ export default class Events {
|
||||
mousemoveInit(art, this);
|
||||
resizeInit(art, this);
|
||||
gestureInit(art, this);
|
||||
viewInit(art, this);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
proxy(target, name, callback, option = {}) {
|
||||
if (Array.isArray(name)) {
|
||||
return name.map(item => this.proxy(target, item, callback, option));
|
||||
return name.map((item) => this.proxy(target, item, callback, option));
|
||||
}
|
||||
|
||||
target.addEventListener(name, callback, option);
|
||||
@@ -67,6 +69,6 @@ export default class Events {
|
||||
}
|
||||
|
||||
destroy() {
|
||||
this.destroyEvents.forEach(event => event());
|
||||
this.destroyEvents.forEach((event) => event());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import { debounce, isInViewport } from '../utils';
|
||||
|
||||
export default function viewInit(art, events) {
|
||||
const {
|
||||
player,
|
||||
option: { autoMin },
|
||||
template: { $container },
|
||||
} = art;
|
||||
|
||||
const scrollFn = debounce(() => {
|
||||
art.emit('view', isInViewport($container));
|
||||
}, 200);
|
||||
|
||||
events.proxy(window, 'scroll', () => {
|
||||
scrollFn();
|
||||
});
|
||||
|
||||
art.on('view', (state) => {
|
||||
if (autoMin) {
|
||||
player.min = !state;
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user