add getPosFromEventMobile

This commit is contained in:
Harvey committed 2022-04-26 18:21:24 +08:00
1 parent 8549661327
commit e862f8d56c
5 files changed
+90 -18

No files matched your search

+12 -3
View File
@@ -9,13 +9,16 @@ export default function gestureInit(art, events) {
let isDroging = false;
let startX = 0;
let startY = 0;
let currentTime = 0;
let pressTimer = null;
events.proxy($video, 'touchstart', (event) => {
if (event.touches.length === 1) {
isDroging = true;
startX = event.touches[0].clientX;
const { clientX, clientY } = event.touches[0];
startX = clientX;
startY = clientY;
clearTimeout(pressTimer);
pressTimer = setTimeout(() => {
@@ -26,11 +29,16 @@ export default function gestureInit(art, events) {
events.proxy($video, 'touchmove', (event) => {
if (event.touches.length === 1 && isDroging) {
const { clientX } = event.touches[0];
const { clientX, clientY } = event.touches[0];
const ratioX = clamp((clientX - startX) / art.width, -1, 1);
const ratioY = clamp((clientY - startY) / art.height, -1, 1);
if (art.duration) {
currentTime = clamp(art.currentTime + art.duration * ratioX, 0, art.duration);
if (art.plugins.autoOrientation && art.plugins.autoOrientation.state) {
currentTime = clamp(art.currentTime + art.duration * ratioY, 0, art.duration);
} else {
currentTime = clamp(art.currentTime + art.duration * ratioX, 0, art.duration);
}
notice.show = `${secondToTime(currentTime)} / ${secondToTime(art.duration)}`;
}
}
@@ -47,6 +55,7 @@ export default function gestureInit(art, events) {
}
startX = 0;
startY = 0;
currentTime = 0;
isDroging = false;
clearTimeout(pressTimer);