html対応

This commit is contained in:
armonica committed 2026-09-07 00:24:17 +09:00
1 parent c9f49ceb44
commit 0048125cc8
1 file changed
+81 -1
+81 -1
View File
@@ -313,6 +313,7 @@ public static class HtmlRenderer
align-items: center;
justify-content: center;
position: relative;
touch-action: pan-y;
}
.slide-image {
@@ -726,6 +727,7 @@ public static class HtmlRenderer
<div class="shortcut-row"><span>全画面表示切替</span><span class="kbd-key">F</span></div>
<div class="shortcut-row"><span>先頭 / 末尾ページへ</span><span class="kbd-key">Home / End</span></div>
<div class="shortcut-row"><span>マウスホイール (スライド時)</span><span class="kbd-key">上: 前 / 下: 次</span></div>
<div class="shortcut-row"><span>左右スワイプ (タッチ操作)</span><span class="kbd-key">左: 次 / 右: 前</span></div>
<div style="margin-top: 20px; text-align: right;">
<button class="action-btn" id="closeHelpBtn">閉じる</button>
</div>
@@ -985,9 +987,87 @@ public static class HtmlRenderer
wheelCooldown = true;
setTimeout(() => {
wheelCooldown = false;
}, 200);
}, 50);
}, { passive: false });
// スマホ・タッチ操作での左右スワイプによるページ送り
let touchStartX = 0;
let touchStartY = 0;
let touchStartTime = 0;
let isTouching = false;
let lastSwipeTime = 0;
window.addEventListener('touchstart', (e) => {
// ヘルプモーダルやサムネイルドロワーが開いているとき、ヘッダー・ツールバー・ボタン・リンクの操作時は除外
if (helpModal.classList.contains('active') || thumbDrawer.classList.contains('active')) return;
if (e.target.closest('header, footer, button, a, input, textarea, .thumb-drawer, .modal')) return;
// マルチタッチ(ピンチズーム等)は除外
if (e.touches.length > 1) {
isTouching = false;
return;
}
const touch = e.touches[0];
touchStartX = touch.clientX;
touchStartY = touch.clientY;
touchStartTime = Date.now();
isTouching = true;
}, { passive: true });
window.addEventListener('touchmove', (e) => {
if (!isTouching || e.touches.length > 1) return;
const touch = e.touches[0];
const diffX = touch.clientX - touchStartX;
const diffY = touch.clientY - touchStartY;
// スライドモード時、水平方向のスワイプであれば縦スクロールやブラウザバウンスを防止
if (isSlideMode && Math.abs(diffX) > Math.abs(diffY) && Math.abs(diffX) > 10) {
if (e.cancelable) {
e.preventDefault();
}
}
}, { passive: false });
window.addEventListener('touchend', (e) => {
if (!isTouching) return;
isTouching = false;
if (!e.changedTouches || e.changedTouches.length === 0) return;
const touch = e.changedTouches[0];
const diffX = touch.clientX - touchStartX;
const diffY = touch.clientY - touchStartY;
const elapsed = Date.now() - touchStartTime;
// スワイプ判定:水平移動量が40px以上、水平移動が垂直移動の1.2倍以上、所要時間600ms以内、直近50ms以上の間隔
const minSwipeDistance = 40;
if (Math.abs(diffX) >= minSwipeDistance &&
Math.abs(diffX) > Math.abs(diffY) * 1.2 &&
elapsed < 600 &&
Date.now() - lastSwipeTime >= 50) {
lastSwipeTime = Date.now();
if (diffX < 0) {
// 左スワイプ(指を右から左へ): 次のページへ
setPage(currentPage + 1);
} else {
// 右スワイプ(指を左から右へ): 前のページへ
setPage(currentPage - 1);
}
}
}, { passive: true });
// スワイプ操作完了直後の誤タップ(clickイベント)を防止
window.addEventListener('click', (e) => {
if (Date.now() - lastSwipeTime < 350) {
e.preventDefault();
e.stopImmediatePropagation();
}
}, true);
setPage(1, false);
</script>
</body>