Skip to content

Commit d3f64a4

Browse files
committed
sticky header
1 parent 3a47031 commit d3f64a4

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

docs/observable.tmpl

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,17 @@
2525
@import url("@fontsource/inter/600-italic.css");
2626
@import url("@fontsource/inter/700-italic.css");
2727
</style>
28+
<style type="text/css">
29+
#header {
30+
transition: box-shadow ease 250ms;
31+
}
32+
#header.scrolled {
33+
box-shadow: 0 0 6px rgba(0, 0, 0, 0.2);
34+
}
35+
</style>
2836
</head>
2937
<body>
30-
<header style="width: 100vw; margin: -32px calc((100% - 100vw) / 2) 4rem; background-color: var(--theme-foreground); color: var(--theme-background); font: 500 16px/normal var(--sans-serif);">
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);">
3139
<div style="display: flex; max-width: var(--max-width); padding: 1rem; margin: auto; gap: 1rem; justify-content: space-between;">
3240
<a href="/notebook-kit/" style="color: inherit; display: flex; align-items: center; gap: 0.5rem;">
3341
<svg role="img" width="24" height="24" viewBox="0 0 24 24" aria-label="Observable" fill="currentColor">
@@ -54,6 +62,15 @@
5462
<script type="module">
5563
document.querySelector("#edit-page").href += `/edit/main/docs${location.pathname.replace(/^\/notebook-kit\//, "/") + (location.pathname.endsWith("/") ? "index" : "")}.html`;
5664
</script>
65+
<script type="module">
66+
let scrolled = false;
67+
const header = document.querySelector("#header");
68+
document.addEventListener("scroll", () => {
69+
const s = scrollY > 0;
70+
if (scrolled === s) return;
71+
header.classList.toggle("scrolled", scrolled = s);
72+
});
73+
</script>
5774
<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);">
5875
<div style="display: flex; flex-wrap: wrap; max-width: var(--max-width); padding: 2rem 1rem; margin: auto; gap: 2rem;">
5976
<div>

0 commit comments

Comments
 (0)