Skip to content

Commit 3b9a2a9

Browse files
committed
优化图片放大圆角过渡效果
- 使用 clip-path 实现放大图圆角,避免 scale 动画影响 - 动画期间移除圆角,结束后平滑过渡恢复 - 使用 CSS 变量 --img-radius 统一管理圆角值
1 parent 0ba877b commit 3b9a2a9

2 files changed

Lines changed: 38 additions & 13 deletions

File tree

src/components/ClientScripts.astro

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,34 @@
9696
bgClickAction: 'close',
9797
bgOpacity: 0.8,
9898
padding: { top: 20, bottom: 20, left: 20, right: 20 },
99+
showHideAnimationType: 'zoom',
100+
showAnimationDuration: 300,
101+
hideAnimationDuration: 300,
99102
});
100103

101-
// Parse data from image tags
102-
lightbox.on('uiRegister', function () {
103-
const pswp = lightbox.pswp;
104+
// Smooth border-radius transition: remove during animation, restore after
105+
let currentThumb: HTMLElement | null = null;
104106

105-
// Add class after zoom animation to handle border radius
106-
// We check if pswp exists (it should inside uiRegister, but safe-check doesn't hurt)
107-
if (pswp) {
108-
}
107+
lightbox.on('openingAnimationStart', () => {
108+
currentThumb = lightbox.pswp?.currSlide?.data?.element as HTMLElement;
109+
currentThumb?.classList.add('pswp-animating');
110+
});
111+
112+
lightbox.on('openingAnimationEnd', () => {
113+
document.querySelector('.pswp')?.classList.add('pswp--anim-complete');
114+
});
109115

116+
lightbox.on('closingAnimationStart', () => {
117+
document.querySelector('.pswp')?.classList.remove('pswp--anim-complete');
118+
});
119+
120+
lightbox.on('closingAnimationEnd', () => {
121+
currentThumb?.classList.remove('pswp-animating');
122+
currentThumb = null;
123+
});
124+
125+
// Parse data from image tags
126+
lightbox.on('uiRegister', function () {
110127
lightbox.pswp.ui.registerElement({
111128
name: 'custom-caption',
112129
order: 9,

src/styles/markdown.css

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ body {
1616
height: auto;
1717
object-fit: cover;
1818
background-color: #f3f4f6;
19-
border-radius: 4px;
19+
border-radius: var(--img-radius, 8px);
20+
}
21+
22+
/* Remove border-radius during PhotoSwipe zoom animation */
23+
.heti img.pswp-animating {
24+
border-radius: 0 !important;
2025
}
2126

2227
.logo img,
@@ -1186,14 +1191,17 @@ img[loading="lazy"] {
11861191
display: none !important;
11871192
}
11881193

1189-
/* Default: Sharp for clean zoom */
1194+
/* PhotoSwipe: smooth border-radius transition using clip-path (unaffected by scale) */
11901195
.pswp__img,
11911196
.pswp__content > img,
1192-
.pswp__zoom-wrap img {
1197+
.pswp__zoom-wrap img,
1198+
.pswp__img--placeholder {
11931199
object-fit: contain;
1194-
border-radius: 0 !important;
1200+
border-radius: 0;
1201+
clip-path: inset(0 round 0);
1202+
transition: clip-path 0.25s ease-out;
11951203
}
11961204

1197-
.pswp__img--placeholder {
1198-
border-radius: 0 !important;
1205+
.pswp--anim-complete .pswp__img {
1206+
clip-path: inset(0 round var(--img-radius, 8px));
11991207
}

0 commit comments

Comments
 (0)