Skip to content

Commit 1796094

Browse files
committed
style: streamline banner behavior and transitions for improved performance and responsiveness across layouts
1 parent 05379b5 commit 1796094

3 files changed

Lines changed: 25 additions & 41 deletions

File tree

src/components/Banner.astro

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ if (!isExternal && src) {
4141
<div
4242
id="banner-wrapper"
4343
class="absolute z-10 w-full overflow-hidden"
44-
style="top: 0"
4544
>
4645
<div
4746
id="banner"

src/layouts/Layout.astro

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -157,26 +157,15 @@ const bannerOffset = (() => {
157157
}
158158

159159
.enable-banner #banner-wrapper {
160-
height: var(--banner-height);
161-
top: 0;
162-
will-change: height, top;
163-
transition: height 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94),
164-
top 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94);
165-
}
166-
167-
.enable-banner #banner {
168-
height: var(--banner-height);
169-
will-change: height;
170-
transition: height 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94);
171-
}
172-
173-
body.is-home.enable-banner #banner-wrapper {
174160
height: var(--banner-height-home);
175161
top: calc(-1 * var(--banner-height-extend));
162+
transform: translateY(0);
163+
will-change: transform;
164+
transition: transform 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94);
176165
}
177166

178-
body.is-home.enable-banner #banner {
179-
height: var(--banner-height-home);
167+
.enable-banner #banner {
168+
height: 100%;
180169
}
181170

182171
#main-grid {
@@ -195,28 +184,27 @@ const bannerOffset = (() => {
195184
height: calc(var(--banner-height-home) - 4.5rem);
196185
}
197186

198-
/* Mobile banner height override - keep base height on mobile */
187+
/* Mobile: disable banner expansion */
199188
@media (max-width: 768px) {
200-
.enable-banner #banner-wrapper {
201-
height: var(--banner-height) !important;
202-
top: 0 !important;
203-
}
204-
205-
.enable-banner #banner {
206-
height: var(--banner-height) !important;
189+
body.is-home.enable-banner #banner-wrapper {
190+
transform: translateY(0) !important;
207191
}
208192

209193
.enable-banner #top-row {
210194
height: calc(var(--banner-height) - 4.5rem) !important;
211195
}
212196
}
213197

214-
/* Ensure main-grid translateY only applies on desktop for home page */
198+
/* Desktop: banner expansion on home page */
215199
@media (min-width: 769px) {
200+
body.is-home.enable-banner #banner-wrapper {
201+
transform: translateY(var(--banner-height-extend));
202+
}
203+
216204
body.is-home.enable-banner #main-grid {
217205
transform: translateY(var(--banner-height-extend));
218206
}
219-
207+
220208
body.is-home.enable-banner #top-row {
221209
height: calc(var(--banner-height-home) - 4.5rem) !important;
222210
}

src/scripts/banner.ts

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,27 +71,24 @@ export function initBannerAndTransitions(): void {
7171
}
7272
});
7373

74-
// handle visit start - prepare animation
75-
(window as any).swup.hooks.on('visit:start', () => {
76-
// increase page height to prevent scrolling jump
77-
const heightExtend = document.getElementById('page-height-extend');
78-
if (heightExtend) {
79-
heightExtend.classList.remove('hidden');
80-
}
81-
});
82-
83-
// handle content replace - trigger banner resize AFTER new content is in DOM
84-
// so the transition is visible during the new page's fade-in, not the old page's fade-out
85-
(window as any).swup.hooks.on('content:replace', () => {
86-
const currentPath = window.location.pathname;
87-
const isTargetHome = pathsEqual(currentPath, '/');
74+
// handle visit start - update banner height immediately on click for synchronized animation
75+
(window as any).swup.hooks.on('visit:start', (visit: any) => {
76+
// change is-home immediately so banner animates in sync with content transition
77+
const targetPath = new URL(visit.to.url, window.location.origin).pathname;
78+
const isTargetHome = pathsEqual(targetPath, '/');
8879
const hasIsHome = document.body.classList.contains('is-home');
8980

9081
if (isTargetHome && !hasIsHome) {
9182
document.body.classList.add('is-home');
9283
} else if (!isTargetHome && hasIsHome) {
9384
document.body.classList.remove('is-home');
9485
}
86+
87+
// increase page height to prevent scrolling jump
88+
const heightExtend = document.getElementById('page-height-extend');
89+
if (heightExtend) {
90+
heightExtend.classList.remove('hidden');
91+
}
9592
});
9693

9794
// handle visit end

0 commit comments

Comments
 (0)