add indicatorGestureInit

This commit is contained in:
Harvey committed 2022-04-27 09:45:47 +08:00
1 parent 99ba0f6131
commit 57a14f63ac
4 files changed
+159 -151

No files matched your search

+2 -40
View File
@@ -1,4 +1,5 @@
import { query, clamp, append, setStyle, setStyles, secondToTime, includeFromEvent, isMobile } from '../utils';
import { indicatorGestureInit } from '../events/gestureInit';
export function getPosFromEvent(art, event) {
const { $progress } = art.template;
@@ -11,27 +12,6 @@ export function getPosFromEvent(art, event) {
return { second, time, width, percentage };
}
export function getPosFromEventMobile(art, event) {
const autoOrientation = art.plugins.autoOrientation && art.plugins.autoOrientation.state;
const { $progress } = art.template;
const { left, top } = $progress.getBoundingClientRect();
const { clientX, clientY } = event.touches[0];
const width = clamp(clientX - left, 0, $progress.clientWidth);
const height = clamp(clientY - top, 0, $progress.clientWidth);
const size = autoOrientation ? height : width;
const secondX = (width / $progress.clientWidth) * art.duration;
const secondY = (height / $progress.clientWidth) * art.duration;
const second = autoOrientation ? secondY : secondX;
const time = secondToTime(second);
const percentage = clamp(size / $progress.clientWidth, 0, 1);
return { second, time, size, percentage };
}
export default function progress(options) {
return (art) => {
const {
@@ -182,25 +162,7 @@ export default function progress(options) {
}
});
proxy($indicator, 'touchstart', (event) => {
if (event.touches.length === 1) {
isDroging = true;
}
});
proxy(document, 'touchmove', (event) => {
if (event.touches.length === 1 && isDroging) {
const { second, percentage } = getPosFromEventMobile(art, event);
setBar('played', percentage);
art.seek = second;
}
});
proxy(document, 'touchend', () => {
if (isDroging) {
isDroging = false;
}
});
indicatorGestureInit(art, $indicator, setBar);
},
};
};