From 44626f8edc6e7183e526bfe156e9100b86a53b0e Mon Sep 17 00:00:00 2001 From: wait4xx Date: Sun, 1 Nov 2026 12:34:11 +0800 Subject: [PATCH] =?UTF-8?q?fix(lightbox):=20=E5=9B=9E=201x=20=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=BD=92=E4=B8=AD+=E5=B9=B3=E7=A7=BB=E5=9B=9B?= =?UTF-8?q?=E5=90=91=E9=92=B3=E5=88=B6=EF=BC=88=E7=94=A8=E6=88=B7=E5=AE=9E?= =?UTF-8?q?=E6=B5=8B=20bug=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 用户实测:缩放回 100% 图片不回中显示不全;另放大态可拖飞出舞台。 三修:zoomAt next<=1 归零 translate;applyZoom 平移钳制 |t|≤尺 寸差/2(放大态不变量=图盒覆盖舞台而非缩在视口内);滚轮下限 0.5x→1x(fit 即最小,0.5x 制造偏移态)。mockup 同步三修。 验证: 回 1x transform=none 实测;四角极限拖拽覆盖舞台不变量 全过;E2E 34/34 Spec: none (用户实测 bug 热修,线上 v2+mockup 双修) Co-authored-by: GLM-5.3 --- design/lightbox-mockup.html | 8 +- src/components/pages/GalleryPage.astro | 117 ++++++++++++++++++++++--- 2 files changed, 111 insertions(+), 14 deletions(-) diff --git a/design/lightbox-mockup.html b/design/lightbox-mockup.html index c303ca6..27b21d7 100644 --- a/design/lightbox-mockup.html +++ b/design/lightbox-mockup.html @@ -238,7 +238,11 @@ function show(i,dir){ } /* ===== 缩放:滚轮锚点 / 双击 / 双指 / 拖拽(复用线上 v2 数学) ===== */ -function applyZoom(){pic.style.transform=`translate(${zoom.tx}px,${zoom.ty}px) scale(${zoom.s})`; +function clampPan(){const mx=Math.max(0,pic.clientWidth*(zoom.s-1)/2), + my=Math.max(0,pic.clientHeight*(zoom.s-1)/2); + zoom.tx=Math.min(mx,Math.max(-mx,zoom.tx));zoom.ty=Math.min(my,Math.max(-my,zoom.ty));} +function applyZoom(){clampPan(); + pic.style.transform=zoom.s===1?'none':`translate(${zoom.tx}px,${zoom.ty}px) scale(${zoom.s})`; pic.classList.toggle('zoomed',zoom.s!==1); lbx.classList.toggle('clean',zoom.s!==1);} function instantResetZoom(){const keep=pic.style.transition;pic.style.transition='none'; @@ -246,7 +250,7 @@ function instantResetZoom(){const keep=pic.style.transition;pic.style.transition lbx.classList.remove('clean');void pic.offsetWidth;pic.style.transition=keep||'';} function zoomAt(next,cx,cy){const r=pic.getBoundingClientRect(); const ax=cx-r.left-r.width/2-zoom.tx,ay=cy-r.top-r.height/2-zoom.ty; - const k=next/zoom.s;zoom.tx-=ax*(k-1);zoom.ty-=ay*(k-1);zoom.s=next;applyZoom();zindShow();} + if(next<=1){zoom={s:1,tx:0,ty:0};applyZoom();zindShow();return;}const k=next/zoom.s;zoom.tx-=ax*(k-1);zoom.ty-=ay*(k-1);zoom.s=next;applyZoom();zindShow();} let zt;function zindShow(){const z=$('zind');z.textContent=Math.round(zoom.s*100)+'%'; z.classList.add('show');clearTimeout(zt);zt=setTimeout(()=>z.classList.remove('show'),900);} lbx.addEventListener('wheel',e=>{if(!open_)return;e.preventDefault(); diff --git a/src/components/pages/GalleryPage.astro b/src/components/pages/GalleryPage.astro index ed6940c..a4c0f1c 100644 --- a/src/components/pages/GalleryPage.astro +++ b/src/components/pages/GalleryPage.astro @@ -51,6 +51,7 @@ const cards = await Promise.all( return { group: photo.data.group, title: photo.data.title, + caption: photo.data.caption ?? '', alt: photo.data.alt ?? photo.data.title, image: photo.data.image, exif: formatExif(photo.data.exif), @@ -92,9 +93,12 @@ const first = cards[0]; type="button" class="shot-btn" data-title={card.title} + data-caption={card.caption} data-exif={card.exif} data-full={card.fullSrc} data-original={card.original} + data-w={card.w} + data-h={card.h} aria-label={t('gallery_view_aria', locale).replace('{title}', card.title) + (card.exif ? t('gallery_view_aria_exif', locale).replace('{exif}', card.exif) : '')} > @@ -130,10 +134,12 @@ const first = cards[0];
- {first?.title} - {first?.exif} - 1 / {cards.length} - +

{first?.caption ?? ''}

+