add autoMin

This commit is contained in:
Harvey committed 2020-05-19 11:47:45 +08:00
1 parent 33a7e1193d
commit b202c21a7f
11 files changed
+150 -18

No files matched your search

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