Skip to content

Commit 1ae7f1b

Browse files
author
lijiaxu2021
committed
fix: replace fancybox <a> wrapper with <span> + placeFocusBack:false to prevent page nav on close
1 parent b6b63df commit 1ae7f1b

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

src/pages/posts/[id].astro

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -418,12 +418,12 @@ const allTalksData = await getProcessedTalks();
418418
images.forEach(img => {
419419
// Skip icons or small decorative images
420420
if (img.width < 40 || img.height < 40) return;
421-
// Skip if already wrapped or has a parent link
422-
if (img.closest('a')) return;
421+
// Skip if already wrapped with fancybox
422+
if (img.closest('[data-fancybox]')) return;
423423

424-
const wrapper = document.createElement('a');
424+
const wrapper = document.createElement('span');
425425
wrapper.setAttribute('data-fancybox', 'gallery');
426-
wrapper.setAttribute('href', img.src);
426+
wrapper.setAttribute('data-src', img.src);
427427
wrapper.setAttribute('data-caption', img.alt || '');
428428
wrapper.className = 'cursor-zoom-in block my-6 overflow-hidden rounded-sm border-4 border-[#0284c7] shadow-[6px_6px_0px_0px_#0284c7] hover:shadow-[10px_10px_0px_0px_#10b981] transition-all duration-300 transform hover:scale-[1.01]';
429429

@@ -442,6 +442,7 @@ const allTalksData = await getProcessedTalks();
442442
try {
443443
Fancybox.destroy();
444444
Fancybox.bind('[data-fancybox]', {
445+
placeFocusBack: false,
445446
carousel: { friction: 0.8 },
446447
Toolbar: {
447448
display: {

0 commit comments

Comments
 (0)