Skip to content

Commit e6c8f41

Browse files
committed
Hide header on scroll down, reveal on scroll up
The fixed header takes up space when users are reading content. Add scroll-direction detection to auto-hide the header when scrolling down and reveal it when scrolling up, using a CSS transform transition. https://claude.ai/code/session_01R5fn9FzwMAomYvf5aNSmCR
1 parent d3f0dbb commit e6c8f41

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

website/static/style.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,11 @@ header {
227227
right: 0;
228228
z-index: 100;
229229
box-shadow: 0 4px 4px rgba(0, 0, 0, 0.4);
230+
transition: transform 0.3s ease;
231+
}
232+
233+
header.header-hidden {
234+
transform: translateY(-100%);
230235
}
231236

232237
header a {

website/template.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,20 @@
3131
</footer>
3232

3333
<script type="module" src="/static/playground.js"></script>
34+
<script>
35+
(function () {
36+
var lastScrollY = window.scrollY;
37+
var header = document.querySelector("header");
38+
window.addEventListener("scroll", function () {
39+
var currentScrollY = window.scrollY;
40+
if (currentScrollY > lastScrollY && currentScrollY > 60) {
41+
header.classList.add("header-hidden");
42+
} else {
43+
header.classList.remove("header-hidden");
44+
}
45+
lastScrollY = currentScrollY;
46+
});
47+
})();
48+
</script>
3449
</body>
3550
</html>

0 commit comments

Comments
 (0)