Skip to content

Commit 2a596f8

Browse files
committed
feat: make hero background use camera-driven crop
1 parent bbba59c commit 2a596f8

6 files changed

Lines changed: 43 additions & 22 deletions

File tree

docs/.vitepress/theme/SimDeckHome.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@ const command = "npm i -g simdeck@latest\nsimdeck";
55
const copied = ref(false);
66
77
function updateNavState() {
8-
const progress = Math.min(Math.max((window.scrollY - 120) / 260, 0), 1);
8+
const scrollY = window.scrollY;
9+
const progress = Math.min(Math.max((scrollY - 120) / 260, 0), 1);
10+
const bgCameraY = Math.min(scrollY * 0.58, window.innerHeight * 0.7);
11+
const bgOpacity = Math.max(1 - scrollY / (window.innerHeight * 0.95), 0);
12+
913
document.documentElement.style.setProperty("--sd-nav-progress", progress.toFixed(3));
14+
document.documentElement.style.setProperty("--sd-hero-bg-camera-y", `${(-bgCameraY).toFixed(1)}px`);
15+
document.documentElement.style.setProperty("--sd-hero-bg-opacity", bgOpacity.toFixed(3));
1016
document.documentElement.classList.toggle("sd-nav-scrolled", progress > 0.02);
1117
}
1218
@@ -20,6 +26,8 @@ onBeforeUnmount(() => {
2026
window.removeEventListener("scroll", updateNavState);
2127
document.documentElement.classList.remove("sd-home-active", "sd-nav-scrolled");
2228
document.documentElement.style.removeProperty("--sd-nav-progress");
29+
document.documentElement.style.removeProperty("--sd-hero-bg-camera-y");
30+
document.documentElement.style.removeProperty("--sd-hero-bg-opacity");
2331
});
2432
2533
async function copyCommand() {

docs/.vitepress/theme/custom.css

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -215,36 +215,47 @@ html:not(.sd-home-active) .VPNavBar.screen-open {
215215

216216
.sd-home {
217217
position: relative;
218+
isolation: isolate;
218219
width: 100vw;
219220
margin-top: calc(-1 * var(--vp-nav-height));
220221
margin-left: calc(50% - 50vw);
221222
padding-top: var(--vp-nav-height);
222223
overflow: hidden;
223-
background:
224-
linear-gradient(
225-
180deg,
226-
rgba(0, 112, 243, 0.026) 0,
227-
rgba(0, 112, 243, 0.014) 18svh,
228-
rgba(0, 112, 243, 0.005) 42svh,
229-
rgba(0, 112, 243, 0) 76svh
230-
),
231-
var(--sd-bg);
224+
background: var(--sd-bg);
232225
}
233226

234-
.dark .sd-home {
235-
background:
236-
linear-gradient(
237-
180deg,
238-
rgba(50, 145, 255, 0.034) 0,
239-
rgba(50, 145, 255, 0.018) 18svh,
240-
rgba(50, 145, 255, 0.006) 42svh,
241-
rgba(50, 145, 255, 0) 76svh
242-
),
243-
var(--sd-bg);
227+
.sd-home::before {
228+
content: "";
229+
position: fixed;
230+
z-index: 0;
231+
inset: 0;
232+
height: 100svh;
233+
pointer-events: none;
234+
background-image: url("/images/background-light-portrait.png");
235+
background-position: center var(--sd-hero-bg-camera-y, 0);
236+
background-repeat: no-repeat;
237+
background-size: auto 170svh;
238+
opacity: var(--sd-hero-bg-opacity, 1);
239+
will-change: opacity, background-position;
240+
}
241+
242+
.dark .sd-home::before {
243+
background-image: url("/images/background-portrait.png");
244+
}
245+
246+
@media (min-width: 641px) {
247+
.sd-home::before {
248+
background-image: url("/images/background-light.png");
249+
}
250+
251+
.dark .sd-home::before {
252+
background-image: url("/images/background.png");
253+
}
244254
}
245255

246256
.sd-home > * {
247257
position: relative;
258+
z-index: 1;
248259
}
249260

250261
.sd-hero,
@@ -267,7 +278,7 @@ html:not(.sd-home-active) .VPNavBar.screen-open {
267278

268279
.sd-hero-copy {
269280
display: flex;
270-
max-width: 860px;
281+
max-width: 980px;
271282
flex-direction: column;
272283
align-items: center;
273284
}
@@ -281,7 +292,7 @@ html:not(.sd-home-active) .VPNavBar.screen-open {
281292
}
282293

283294
.sd-home .sd-hero-copy p {
284-
max-width: 640px;
295+
max-width: 920px;
285296
margin: 24px auto 0;
286297
color: var(--sd-muted);
287298
font-size: 28px;
@@ -1053,6 +1064,7 @@ html:not(.sd-home-active) .VPNavBar.screen-open {
10531064
}
10541065

10551066
.sd-home .sd-hero-copy p {
1067+
max-width: 680px;
10561068
font-size: 24px;
10571069
}
10581070

@@ -1117,6 +1129,7 @@ html:not(.sd-home-active) .VPNavBar.screen-open {
11171129
}
11181130

11191131
.sd-home .sd-hero-copy p {
1132+
max-width: 100%;
11201133
margin-top: 18px;
11211134
font-size: 23px;
11221135
line-height: 1.18;
1.15 MB
Loading
1.49 MB
Loading
1.35 MB
Loading

docs/public/images/background.png

1.1 MB
Loading

0 commit comments

Comments
 (0)