fix(viewer): 縦スクロール/スライド切替、サムネイルドロワー開閉、下部ツールバー及びキーボード操作を完全実装
This commit is contained in:
1 parent
a59a66a08a
commit
9fb915c882
1 file changed
+554
-59
@@ -885,6 +885,9 @@ public static class UnifiedHtmlRenderer
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
margin: 12px 0;
|
||||
padding: 0 16px;
|
||||
max-width: 960px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.tag-pill {
|
||||
@@ -896,16 +899,7 @@ public static class UnifiedHtmlRenderer
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
|
||||
/* ビューアーレイアウト */
|
||||
.viewer-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
min-height: calc(100vh - var(--header-height));
|
||||
padding-bottom: 80px;
|
||||
}
|
||||
|
||||
/* コントロールバー */
|
||||
.viewer-controls-bar {
|
||||
position: sticky;
|
||||
top: var(--header-height);
|
||||
@@ -914,11 +908,11 @@ public static class UnifiedHtmlRenderer
|
||||
backdrop-filter: blur(16px);
|
||||
-webkit-backdrop-filter: blur(16px);
|
||||
border-bottom: 1px solid var(--border-subtle);
|
||||
padding: 10px 24px;
|
||||
padding: 8px 24px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
z-index: 900;
|
||||
z-index: 890;
|
||||
flex-wrap: wrap;
|
||||
gap: 12px;
|
||||
}
|
||||
@@ -926,33 +920,55 @@ public static class UnifiedHtmlRenderer
|
||||
.control-group {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.view-mode-btn {
|
||||
background: rgba(255, 255, 255, 0.06);
|
||||
background: rgba(255, 255, 255, 0.08);
|
||||
border: 1px solid var(--border-subtle);
|
||||
color: var(--text-main);
|
||||
padding: 6px 12px;
|
||||
padding: 7px 14px;
|
||||
border-radius: 8px;
|
||||
font-size: 0.82rem;
|
||||
font-size: 0.85rem;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
.view-mode-btn:hover {
|
||||
background: rgba(255, 255, 255, 0.15);
|
||||
border-color: rgba(255, 255, 255, 0.25);
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
.view-mode-btn.active {
|
||||
background: var(--accent-gradient-gallery);
|
||||
color: #fff;
|
||||
border-color: transparent;
|
||||
box-shadow: 0 0 15px rgba(99, 102, 241, 0.4);
|
||||
}
|
||||
|
||||
.images-stream {
|
||||
/* メインビューアーコンテナ */
|
||||
.viewer-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
max-width: 900px;
|
||||
min-height: calc(100vh - var(--header-height) - 50px);
|
||||
padding-bottom: 70px;
|
||||
}
|
||||
|
||||
/* 縦スクロールモード */
|
||||
.scroll-mode-view {
|
||||
width: 100%;
|
||||
max-width: 960px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
padding: 24px 16px;
|
||||
padding: 16px 16px 40px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
@@ -964,7 +980,8 @@ public static class UnifiedHtmlRenderer
|
||||
background: rgba(0, 0, 0, 0.3);
|
||||
border-radius: 12px;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
|
||||
box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
|
||||
min-height: 200px;
|
||||
}
|
||||
|
||||
.scroll-image-wrapper img {
|
||||
@@ -983,46 +1000,192 @@ public static class UnifiedHtmlRenderer
|
||||
position: absolute;
|
||||
bottom: 12px;
|
||||
right: 12px;
|
||||
background: rgba(0, 0, 0, 0.7);
|
||||
background: rgba(0, 0, 0, 0.75);
|
||||
backdrop-filter: blur(8px);
|
||||
color: #fff;
|
||||
font-size: 0.75rem;
|
||||
padding: 3px 8px;
|
||||
padding: 3px 10px;
|
||||
border-radius: 6px;
|
||||
font-family: monospace;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
/* サムネイルドロワー */
|
||||
/* スライド(単ページ)モード */
|
||||
.slide-mode-view {
|
||||
display: none;
|
||||
position: fixed;
|
||||
top: calc(var(--header-height) + 48px);
|
||||
bottom: 56px;
|
||||
left: 0;
|
||||
right: 0;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
overflow: hidden;
|
||||
background: #000;
|
||||
z-index: 850;
|
||||
}
|
||||
|
||||
.slide-mode-view.active {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.slide-stage {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
position: relative;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.slide-image {
|
||||
max-width: 100%;
|
||||
max-height: 100%;
|
||||
object-fit: contain;
|
||||
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8);
|
||||
transition: transform 0.15s ease-out;
|
||||
}
|
||||
|
||||
.slide-nav-zone {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
width: 30%;
|
||||
z-index: 10;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
opacity: 0;
|
||||
transition: opacity 0.2s ease;
|
||||
}
|
||||
|
||||
.slide-nav-zone:hover {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.slide-nav-prev {
|
||||
left: 0;
|
||||
justify-content: flex-start;
|
||||
padding-left: 20px;
|
||||
background: linear-gradient(to right, rgba(0, 0, 0, 0.5), transparent);
|
||||
}
|
||||
|
||||
.slide-nav-next {
|
||||
right: 0;
|
||||
justify-content: flex-end;
|
||||
padding-right: 20px;
|
||||
background: linear-gradient(to left, rgba(0, 0, 0, 0.5), transparent);
|
||||
}
|
||||
|
||||
.nav-arrow-icon {
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
border-radius: 50%;
|
||||
background: rgba(15, 20, 34, 0.85);
|
||||
border: 1px solid var(--border-subtle);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: #fff;
|
||||
font-size: 1.2rem;
|
||||
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.6);
|
||||
}
|
||||
|
||||
/* サムネイルドロワー & オーバーレイ */
|
||||
.drawer-overlay {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
background: rgba(0, 0, 0, 0.65);
|
||||
backdrop-filter: blur(4px);
|
||||
opacity: 0;
|
||||
pointer-events: none;
|
||||
transition: opacity 0.25s ease;
|
||||
z-index: 940;
|
||||
}
|
||||
|
||||
.drawer-overlay.active {
|
||||
opacity: 1;
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
.thumb-drawer {
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
background: var(--bg-glass);
|
||||
backdrop-filter: blur(20px);
|
||||
height: 180px;
|
||||
background: var(--bg-surface);
|
||||
border-top: 1px solid var(--border-subtle);
|
||||
padding: 10px 16px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
z-index: 950;
|
||||
transform: translateY(100%);
|
||||
transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
|
||||
box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.6);
|
||||
}
|
||||
|
||||
.thumb-drawer.active {
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
.thumb-drawer-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 8px 16px;
|
||||
background: rgba(0, 0, 0, 0.3);
|
||||
border-bottom: 1px solid var(--border-subtle);
|
||||
font-size: 0.85rem;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.close-drawer-btn {
|
||||
background: transparent;
|
||||
border: none;
|
||||
color: var(--text-muted);
|
||||
font-size: 1.1rem;
|
||||
cursor: pointer;
|
||||
padding: 4px 8px;
|
||||
border-radius: 4px;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.close-drawer-btn:hover {
|
||||
color: #fff;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
|
||||
.thumb-drawer-body {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
overflow-x: auto;
|
||||
z-index: 950;
|
||||
max-height: 110px;
|
||||
padding: 10px 16px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.thumb-item {
|
||||
flex-shrink: 0;
|
||||
width: 60px;
|
||||
height: 80px;
|
||||
width: 75px;
|
||||
height: 105px;
|
||||
position: relative;
|
||||
cursor: pointer;
|
||||
border-radius: 6px;
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
border: 2px solid transparent;
|
||||
transition: border-color 0.2s;
|
||||
transition: all 0.2s ease;
|
||||
background: rgba(0, 0, 0, 0.4);
|
||||
}
|
||||
|
||||
.thumb-item:hover {
|
||||
border-color: rgba(99, 102, 241, 0.5);
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
|
||||
.thumb-item.active {
|
||||
border-color: var(--accent-primary);
|
||||
box-shadow: 0 0 12px rgba(99, 102, 241, 0.6);
|
||||
}
|
||||
|
||||
.thumb-item img {
|
||||
@@ -1036,10 +1199,95 @@ public static class UnifiedHtmlRenderer
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
background: rgba(0, 0, 0, 0.7);
|
||||
background: rgba(0, 0, 0, 0.75);
|
||||
color: #fff;
|
||||
font-size: 0.65rem;
|
||||
font-size: 0.7rem;
|
||||
text-align: center;
|
||||
padding: 1px 0;
|
||||
font-family: monospace;
|
||||
}
|
||||
|
||||
/* 下部固定ツールバー */
|
||||
.bottom-toolbar {
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
height: 56px;
|
||||
background: var(--bg-glass);
|
||||
backdrop-filter: blur(16px);
|
||||
-webkit-backdrop-filter: blur(16px);
|
||||
border-top: 1px solid var(--border-subtle);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 0 20px;
|
||||
z-index: 920;
|
||||
}
|
||||
|
||||
.toolbar-left, .toolbar-right {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.toolbar-btn {
|
||||
background: rgba(255, 255, 255, 0.08);
|
||||
border: 1px solid var(--border-subtle);
|
||||
color: var(--text-main);
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
border-radius: 8px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
cursor: pointer;
|
||||
font-size: 1.1rem;
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
.toolbar-btn:hover {
|
||||
background: var(--accent-primary);
|
||||
border-color: var(--accent-primary);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.page-counter {
|
||||
font-family: 'Outfit', sans-serif;
|
||||
font-size: 0.95rem;
|
||||
font-weight: 600;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.current-page {
|
||||
color: var(--text-main);
|
||||
font-size: 1.15rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.progress-bar-container {
|
||||
flex: 1;
|
||||
max-width: 450px;
|
||||
margin: 0 20px;
|
||||
height: 6px;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border-radius: 3px;
|
||||
overflow: hidden;
|
||||
cursor: pointer;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.progress-bar-fill {
|
||||
height: 100%;
|
||||
width: 0%;
|
||||
background: var(--accent-gradient);
|
||||
transition: width 0.15s ease;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.progress-bar-container { display: none; }
|
||||
.viewer-controls-bar { padding: 8px 12px; }
|
||||
.bottom-toolbar { padding: 0 12px; }
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
@@ -1069,48 +1317,295 @@ public static class UnifiedHtmlRenderer
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="viewer-container">
|
||||
<div class="viewer-controls-bar">
|
||||
<div class="control-group">
|
||||
<span style="font-weight: 700; font-size: 0.95rem;">{{safeTitle}}</span>
|
||||
<span style="color: var(--text-muted); font-size: 0.82rem;">(全{{totalPages}}ページ)</span>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<button id="scrollModeBtn" class="view-mode-btn active">縦スクロール</button>
|
||||
<button id="toggleThumbsBtn" class="view-mode-btn">サムネイル切替</button>
|
||||
</div>
|
||||
<!-- コントロールバー -->
|
||||
<div class="viewer-controls-bar">
|
||||
<div class="control-group">
|
||||
<span style="font-weight: 700; font-size: 0.95rem;">{{safeTitle}}</span>
|
||||
<span style="color: var(--text-muted); font-size: 0.82rem;">(全{{totalPages}}ページ)</span>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<button id="modeToggleBtn" class="view-mode-btn" title="表示モード切替 (M)">📑 スライド表示へ</button>
|
||||
<button id="thumbToggleBtn" class="view-mode-btn" title="サムネイル一覧開閉 (T)">🖼️ サムネイル</button>
|
||||
<button id="fullscreenBtn" class="view-mode-btn" title="全画面表示 (F)">⛶ 全画面</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="viewer-container">
|
||||
{{tagsHtml}}
|
||||
|
||||
<div class="images-stream" id="imagesStream">
|
||||
<!-- 縦スクロールモード -->
|
||||
<div class="scroll-mode-view" id="scrollModeView">
|
||||
{{imagesHtml}}
|
||||
</div>
|
||||
|
||||
<div class="thumb-drawer" id="thumbDrawer">
|
||||
{{thumbsHtml}}
|
||||
<!-- スライドモード -->
|
||||
<div class="slide-mode-view" id="slideModeView">
|
||||
<div class="slide-stage">
|
||||
<div class="slide-nav-zone slide-nav-prev" id="slidePrevZone" title="前のページ (← / A)">
|
||||
<div class="nav-arrow-icon">❮</div>
|
||||
</div>
|
||||
<img id="currentSlideImage" class="slide-image" src="" alt="" />
|
||||
<div class="slide-nav-zone slide-nav-next" id="slideNextZone" title="次のページ (→ / D / Space)">
|
||||
<div class="nav-arrow-icon">❯</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- サムネイルドロワー & オーバーレイ -->
|
||||
<div class="drawer-overlay" id="drawerOverlay"></div>
|
||||
<div class="thumb-drawer" id="thumbDrawer">
|
||||
<div class="thumb-drawer-header">
|
||||
<span>📖 サムネイル一覧 (全{{totalPages}}ページ)</span>
|
||||
<button id="closeDrawerBtn" class="close-drawer-btn" title="閉じる">✕</button>
|
||||
</div>
|
||||
<div class="thumb-drawer-body">
|
||||
{{thumbsHtml}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 下部固定ツールバー -->
|
||||
<footer class="bottom-toolbar" id="bottomToolbar">
|
||||
<div class="toolbar-left">
|
||||
<button id="prevPageBtn" class="toolbar-btn" title="前のページ (← / A)">‹</button>
|
||||
<div class="page-counter">
|
||||
<span id="currentPageDisplay" class="current-page">1</span> / <span class="total-pages">{{totalPages}}</span>
|
||||
</div>
|
||||
<button id="nextPageBtn" class="toolbar-btn" title="次のページ (→ / D / Space)">›</button>
|
||||
</div>
|
||||
|
||||
<div class="progress-bar-container" id="progressBar" title="クリックしてページジャンプ">
|
||||
<div class="progress-bar-fill" id="progressFill"></div>
|
||||
</div>
|
||||
|
||||
<div class="toolbar-right">
|
||||
<button id="toolbarThumbBtn" class="toolbar-btn" title="サムネイル一覧 (T)">🖼️</button>
|
||||
<button id="toolbarFullscreenBtn" class="toolbar-btn" title="全画面切替 (F)">⛶</button>
|
||||
</div>
|
||||
</footer>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const galleryData = {{galleryJson}};
|
||||
const toggleThumbsBtn = document.getElementById('toggleThumbsBtn');
|
||||
const thumbDrawer = document.getElementById('thumbDrawer');
|
||||
const totalPages = {{totalPages}};
|
||||
let currentPage = 1;
|
||||
let isSlideMode = false;
|
||||
|
||||
toggleThumbsBtn.addEventListener('click', () => {
|
||||
thumbDrawer.style.display = thumbDrawer.style.display === 'none' ? 'flex' : 'none';
|
||||
const modeToggleBtn = document.getElementById('modeToggleBtn');
|
||||
const thumbToggleBtn = document.getElementById('thumbToggleBtn');
|
||||
const toolbarThumbBtn = document.getElementById('toolbarThumbBtn');
|
||||
const thumbDrawer = document.getElementById('thumbDrawer');
|
||||
const drawerOverlay = document.getElementById('drawerOverlay');
|
||||
const closeDrawerBtn = document.getElementById('closeDrawerBtn');
|
||||
const scrollModeView = document.getElementById('scrollModeView');
|
||||
const slideModeView = document.getElementById('slideModeView');
|
||||
const currentSlideImage = document.getElementById('currentSlideImage');
|
||||
const slidePrevZone = document.getElementById('slidePrevZone');
|
||||
const slideNextZone = document.getElementById('slideNextZone');
|
||||
const prevPageBtn = document.getElementById('prevPageBtn');
|
||||
const nextPageBtn = document.getElementById('nextPageBtn');
|
||||
const currentPageDisplay = document.getElementById('currentPageDisplay');
|
||||
const progressFill = document.getElementById('progressFill');
|
||||
const progressBar = document.getElementById('progressBar');
|
||||
const fullscreenBtn = document.getElementById('fullscreenBtn');
|
||||
const toolbarFullscreenBtn = document.getElementById('toolbarFullscreenBtn');
|
||||
const thumbItems = document.querySelectorAll('.thumb-item');
|
||||
|
||||
// モード切替(縦スクロール ⇔ スライド)
|
||||
function toggleMode() {
|
||||
isSlideMode = !isSlideMode;
|
||||
if (isSlideMode) {
|
||||
scrollModeView.style.display = 'none';
|
||||
slideModeView.classList.add('active');
|
||||
modeToggleBtn.innerHTML = '📜 スクロール表示へ';
|
||||
modeToggleBtn.classList.add('active');
|
||||
updateSlideImage();
|
||||
} else {
|
||||
slideModeView.classList.remove('active');
|
||||
scrollModeView.style.display = 'flex';
|
||||
modeToggleBtn.innerHTML = '📑 スライド表示へ';
|
||||
modeToggleBtn.classList.remove('active');
|
||||
scrollToPage(currentPage);
|
||||
}
|
||||
}
|
||||
|
||||
// ページ設定
|
||||
function setPage(page, smoothScroll = true) {
|
||||
if (page < 1) page = 1;
|
||||
if (page > totalPages) page = totalPages;
|
||||
currentPage = page;
|
||||
|
||||
currentPageDisplay.textContent = currentPage;
|
||||
const progress = ((currentPage - 1) / Math.max(1, totalPages - 1)) * 100;
|
||||
progressFill.style.width = `${progress}%`;
|
||||
|
||||
// サムネイルのアクティブ状態更新
|
||||
thumbItems.forEach(item => {
|
||||
const p = parseInt(item.getAttribute('data-page'));
|
||||
item.classList.toggle('active', p === currentPage);
|
||||
});
|
||||
|
||||
if (isSlideMode) {
|
||||
updateSlideImage();
|
||||
} else if (smoothScroll) {
|
||||
scrollToPage(currentPage);
|
||||
}
|
||||
}
|
||||
|
||||
// スライド画像更新とプリロード
|
||||
function updateSlideImage() {
|
||||
if (galleryData.images && galleryData.images[currentPage - 1]) {
|
||||
const img = galleryData.images[currentPage - 1];
|
||||
currentSlideImage.src = img.imageUrl;
|
||||
currentSlideImage.alt = img.altText || `${galleryData.title} ${currentPage}ページ`;
|
||||
preloadAdjacent();
|
||||
}
|
||||
}
|
||||
|
||||
function preloadAdjacent() {
|
||||
if (!galleryData.images) return;
|
||||
if (currentPage < totalPages) {
|
||||
const nextImg = new Image();
|
||||
nextImg.src = galleryData.images[currentPage].imageUrl;
|
||||
}
|
||||
if (currentPage > 1) {
|
||||
const prevImg = new Image();
|
||||
prevImg.src = galleryData.images[currentPage - 2].imageUrl;
|
||||
}
|
||||
}
|
||||
|
||||
// 該当ページへのスクロール
|
||||
function scrollToPage(page) {
|
||||
const target = document.querySelector(`.scroll-image-wrapper[data-page="${page}"]`);
|
||||
if (target) {
|
||||
const offset = 120;
|
||||
const bodyRect = document.body.getBoundingClientRect().top;
|
||||
const elementRect = target.getBoundingClientRect().top;
|
||||
const elementPosition = elementRect - bodyRect;
|
||||
const offsetPosition = elementPosition - offset;
|
||||
|
||||
window.scrollTo({
|
||||
top: offsetPosition,
|
||||
behavior: 'smooth'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// サムネイルドロワー開閉
|
||||
function toggleDrawer(open) {
|
||||
const shouldOpen = open !== undefined ? open : !thumbDrawer.classList.contains('active');
|
||||
thumbDrawer.classList.toggle('active', shouldOpen);
|
||||
drawerOverlay.classList.toggle('active', shouldOpen);
|
||||
thumbToggleBtn.classList.toggle('active', shouldOpen);
|
||||
if (shouldOpen) {
|
||||
const activeThumb = document.querySelector(`.thumb-item[data-page="${currentPage}"]`);
|
||||
if (activeThumb) {
|
||||
setTimeout(() => activeThumb.scrollIntoView({ behavior: 'smooth', inline: 'center' }), 120);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 全画面切替
|
||||
function toggleFullscreen() {
|
||||
if (!document.fullscreenElement) {
|
||||
document.documentElement.requestFullscreen().catch(() => {});
|
||||
} else {
|
||||
document.exitFullscreen().catch(() => {});
|
||||
}
|
||||
}
|
||||
|
||||
// スクロール検知によるページ追従
|
||||
let scrollTimer;
|
||||
window.addEventListener('scroll', () => {
|
||||
if (isSlideMode) return;
|
||||
clearTimeout(scrollTimer);
|
||||
scrollTimer = setTimeout(() => {
|
||||
const wrappers = document.querySelectorAll('.scroll-image-wrapper');
|
||||
const viewCenter = window.innerHeight / 2;
|
||||
let found = currentPage;
|
||||
|
||||
wrappers.forEach(w => {
|
||||
const rect = w.getBoundingClientRect();
|
||||
if (rect.top <= viewCenter && rect.bottom >= viewCenter) {
|
||||
found = parseInt(w.getAttribute('data-page'));
|
||||
}
|
||||
});
|
||||
|
||||
if (found !== currentPage) {
|
||||
setPage(found, false);
|
||||
}
|
||||
}, 60);
|
||||
});
|
||||
|
||||
// サムネイルクリック時のジャンプ
|
||||
document.querySelectorAll('.thumb-item').forEach(item => {
|
||||
// イベントリスナー登録
|
||||
modeToggleBtn.addEventListener('click', toggleMode);
|
||||
thumbToggleBtn.addEventListener('click', () => toggleDrawer());
|
||||
toolbarThumbBtn.addEventListener('click', () => toggleDrawer());
|
||||
closeDrawerBtn.addEventListener('click', () => toggleDrawer(false));
|
||||
drawerOverlay.addEventListener('click', () => toggleDrawer(false));
|
||||
|
||||
prevPageBtn.addEventListener('click', () => setPage(currentPage - 1));
|
||||
nextPageBtn.addEventListener('click', () => setPage(currentPage + 1));
|
||||
slidePrevZone.addEventListener('click', () => setPage(currentPage - 1));
|
||||
slideNextZone.addEventListener('click', () => setPage(currentPage + 1));
|
||||
|
||||
fullscreenBtn.addEventListener('click', toggleFullscreen);
|
||||
toolbarFullscreenBtn.addEventListener('click', toggleFullscreen);
|
||||
|
||||
// プログレスバークリック
|
||||
progressBar.addEventListener('click', (e) => {
|
||||
const rect = progressBar.getBoundingClientRect();
|
||||
const ratio = (e.clientX - rect.left) / rect.width;
|
||||
const targetPage = Math.max(1, Math.min(totalPages, Math.round(ratio * totalPages)));
|
||||
setPage(targetPage);
|
||||
});
|
||||
|
||||
// サムネイルクリック
|
||||
thumbItems.forEach(item => {
|
||||
item.addEventListener('click', () => {
|
||||
const page = item.getAttribute('data-page');
|
||||
const targetImg = document.querySelector(`.scroll-image-wrapper[data-page="${page}"]`);
|
||||
if (targetImg) {
|
||||
targetImg.scrollIntoView({ behavior: 'smooth' });
|
||||
}
|
||||
const page = parseInt(item.getAttribute('data-page'));
|
||||
setPage(page);
|
||||
toggleDrawer(false);
|
||||
});
|
||||
});
|
||||
|
||||
// キーボード操作
|
||||
window.addEventListener('keydown', (e) => {
|
||||
if (e.target.tagName === 'INPUT' || e.target.tagName === 'TEXTAREA') return;
|
||||
|
||||
switch (e.key) {
|
||||
case 'ArrowRight':
|
||||
case 'd':
|
||||
case 'D':
|
||||
case ' ':
|
||||
e.preventDefault();
|
||||
setPage(currentPage + 1);
|
||||
break;
|
||||
case 'ArrowLeft':
|
||||
case 'a':
|
||||
case 'A':
|
||||
e.preventDefault();
|
||||
setPage(currentPage - 1);
|
||||
break;
|
||||
case 'm':
|
||||
case 'M':
|
||||
toggleMode();
|
||||
break;
|
||||
case 't':
|
||||
case 'T':
|
||||
toggleDrawer();
|
||||
break;
|
||||
case 'f':
|
||||
case 'F':
|
||||
toggleFullscreen();
|
||||
break;
|
||||
case 'Escape':
|
||||
toggleDrawer(false);
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
// 初期表示設定
|
||||
setPage(1, false);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in new issue
Block a user