Skip to content

Commit 902352e

Browse files
committed
fancier sticky header
1 parent d3f64a4 commit 902352e

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

docs/observable.tmpl

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,23 @@
2727
</style>
2828
<style type="text/css">
2929
#header {
30-
transition: box-shadow ease 250ms;
30+
background: var(--theme-foreground);
31+
color: var(--theme-background);
32+
transition: box-shadow ease 250ms,
33+
background-color linear 250ms,
34+
color linear 250ms;
3135
}
32-
#header.scrolled {
36+
#header.scrolled1 {
3337
box-shadow: 0 0 6px rgba(0, 0, 0, 0.2);
3438
}
39+
#header.scrolled2 {
40+
background: var(--theme-background);
41+
color: var(--theme-foreground);
42+
}
3543
</style>
3644
</head>
3745
<body>
38-
<header id="header" style="position: sticky; z-index: 10; top: 0; margin: -32px calc((100% - 100vw) / 2) 4rem; background: var(--theme-foreground); color: var(--theme-background); font: 500 16px/normal var(--sans-serif);">
46+
<header id="header" style="position: sticky; z-index: 10; top: 0; margin: -32px calc((100% - 100vw) / 2) 4rem; font: 500 16px/normal var(--sans-serif);">
3947
<div style="display: flex; max-width: var(--max-width); padding: 1rem; margin: auto; gap: 1rem; justify-content: space-between;">
4048
<a href="/notebook-kit/" style="color: inherit; display: flex; align-items: center; gap: 0.5rem;">
4149
<svg role="img" width="24" height="24" viewBox="0 0 24 24" aria-label="Observable" fill="currentColor">
@@ -63,12 +71,21 @@
6371
document.querySelector("#edit-page").href += `/edit/main/docs${location.pathname.replace(/^\/notebook-kit\//, "/") + (location.pathname.endsWith("/") ? "index" : "")}.html`;
6472
</script>
6573
<script type="module">
66-
let scrolled = false;
74+
let scrolled1 = false;
6775
const header = document.querySelector("#header");
6876
document.addEventListener("scroll", () => {
6977
const s = scrollY > 0;
70-
if (scrolled === s) return;
71-
header.classList.toggle("scrolled", scrolled = s);
78+
if (scrolled1 === s) return;
79+
header.classList.toggle("scrolled1", scrolled1 = s);
80+
});
81+
</script>
82+
<script type="module">
83+
let scrolled2 = false;
84+
document.addEventListener("scroll", () => {
85+
const c = document.querySelector(".observablehq--cell");
86+
const s = c?.getBoundingClientRect().bottom < 50;
87+
if (scrolled2 === s) return;
88+
header.classList.toggle("scrolled2", scrolled2 = s);
7289
});
7390
</script>
7491
<footer style="width: 100vw; margin: 2rem calc((100% - 100vw) / 2) -32px; padding-bottom: 16px; background-color: var(--theme-foreground); color: var(--theme-background); font: 12px/normal var(--sans-serif);">

0 commit comments

Comments
 (0)