Skip to content

Commit 1670f5c

Browse files
committed
fix: banner-single-container重复创建子元素 #376
1 parent 38189eb commit 1670f5c

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

src/layouts/MainGridLayout.astro

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -670,11 +670,16 @@ const transparentClass = shouldEnableTransparency
670670
return images || null;
671671
};
672672

673+
const container = document.getElementById('banner-single-container');
674+
675+
// 检查容器是否已有图片,避免在页面切换或缩放时重复创建
676+
if (container.querySelector('img')) {
677+
return;
678+
}
679+
673680
const desktopSrc = getRandomImage(desktopImages, 'banner_desktop_index');
674681
const mobileSrc = getRandomImage(mobileImages, 'banner_mobile_index');
675682

676-
const container = document.getElementById('banner-single-container');
677-
678683
if (mobileSrc) {
679684
const mobileImg = document.createElement('img');
680685
mobileImg.alt = 'Mobile banner image of the blog';

0 commit comments

Comments
 (0)