跳跃式位置移动,暂不平滑

This commit is contained in:
WindowBird 2025-11-03 09:18:31 +08:00
parent ea139100e6
commit 9169b7e838

View File

@ -215,6 +215,7 @@ const translateX = ref(-375); // 当前滑动偏移量,初始值设为 -375
const baseTranslateX = ref(-375); //
const isAnimating = ref(false); //
const isDragging = ref(false); //
const isInitialized = ref(false); //
//
const initScreenWidth = () => {
@ -222,10 +223,11 @@ const initScreenWidth = () => {
success: (res) => {
const width = res.windowWidth || res.screenWidth || 375;
screenWidth.value = width;
//
if (translateX.value === -375) {
//
if (!isInitialized.value) {
translateX.value = -width;
baseTranslateX.value = -width;
isInitialized.value = true;
}
}
});
@ -249,10 +251,10 @@ const handleTouchMove = (e) => {
const deltaX = touch.clientX - touchStartX.value;
const deltaY = Math.abs(touch.clientY - touchStartY.value);
//
if (Math.abs(deltaX) > deltaY && Math.abs(deltaX) > 10) {
e.preventDefault();
}
// //
// if (Math.abs(deltaX) > deltaY && Math.abs(deltaX) > 10) {
// e.preventDefault();
// }
//
translateX.value = baseTranslateX.value + deltaX;
@ -280,10 +282,10 @@ const handleTouchEnd = (e) => {
if (isHorizontalSwipe) {
//
if (deltaX > 0) {
//
// slideToPreviousDay();
//
slideToPreviousDay();
} else {
//
//
slideToNextDay();
}
} else {
@ -306,12 +308,12 @@ const resetToCenter = () => {
const slideToPreviousDay = () => {
isAnimating.value = true;
// -screenWidth * 2
const targetX = -screenWidth.value*2;
translateX.value = targetX;
// const targetX = -screenWidth.value*2;
// translateX.value = targetX;
setTimeout(() => {
// transition
isAnimating.value = false;
// isAnimating.value = false;
// transition
setTimeout(() => {
@ -327,14 +329,15 @@ const slideToPreviousDay = () => {
console.log(`日期切换:上一天,新日期:${selectedDate.value}`);
}, 16); // transition
}, 1000);
isAnimating.value = false;
};
//
const slideToNextDay = () => {
isAnimating.value = true;
// 0
const targetX = 0;
translateX.value = targetX;
// const targetX = 0;
// translateX.value = targetX;
setTimeout(() => {
// transition
@ -353,7 +356,7 @@ const slideToNextDay = () => {
console.log(`日期切换:下一天,新日期:${selectedDate.value}`);
}, 16); // transition
}, 1000);
}, 300);
};
//