原代碼中 `swipeUp` 翻頁邏輯:
if (last.row != 10) { now.row = last.row + 1; now.col = 1; pageMove(towards.up); }
`last.row != 10` 控制最大頁數為 10。`swipeDown` 中 `last.row != 1` 控制最小頁數。
// 向上翻頁 (下一頁)
$(document).swipeUp(function() {
if (isAnimating) return;
last.row = now.row;
last.col = now.col;
// 修改 10 → 3
if (last.row != 3) {
now.row = last.row + 1;
now.col = 1;
pageMove(towards.up);
}
});
// 向下翻頁 (上一頁)
$(document).swipeDown(function() {
if (isAnimating) return;
last.row = now.row;
last.col = now.col;
if (last.row != 1) { // 最小頁碼保持 1
now.row = last.row - 1;
now.col = 1;
pageMove(towards.down);
}
});
const MAX_PAGE = 3; // 可從後端獲取或配置
const MIN_PAGE = 1;
$(document).swipeUp(function() {
if (isAnimating) return;
if (now.row < MAX_PAGE) {
last.row = now.row;
last.col = now.col;
now.row++;
now.col = 1;
pageMove(towards.up);
}
});
$(document).swipeDown(function() {
if (isAnimating) return;
if (now.row > MIN_PAGE) {
last.row = now.row;
last.col = now.col;
now.row--;
now.col = 1;
pageMove(towards.down);
}
});
HTML 中需恰好存在 `.page-1-1`、`.page-2-1`、`.page-3-1` 三個頁面容器,CSS 動畫類 `pt-page-moveToTop` 等正確定義。
核心邏輯:**`now.row` 代表當前頁碼,邊界判斷直接控制最大/最小頁數**。