Fixed header that will gradually disappear when the page is scrolled down | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Fixed header that will gradually disappear when the page is scrolled down

How can I design a fixed header that will gradually disappear when the page is scrolled down. My header contains a nav bar and a brand logo. I want it to be fix on top but gradually disappear when the scroll bar is rolled down the page.

31st Aug 2020, 6:57 AM
DN Josh
DN Josh - avatar
4 Answers
+ 5
Make a scroll event / something that happens when someone scrolls, then check window's pageYOffset, if its greater than your navbar's height, just turn its display to none, or whatever animation u want. let header = document.querySelector("header") window.onscroll = (e)=> { if (window.pageYOffset > 70) { header.style.display = "none" } else { header.style.display = "block" } }
31st Aug 2020, 7:11 AM
maf
maf - avatar
+ 3
just simply have one header and style it as you want using CSS. Then in JavaScript, handle onscroll event and perform any animation you want to.
31st Aug 2020, 7:05 AM
Raj Chhatrala
Raj Chhatrala - avatar
+ 1
🔫 Rick Grimes not really clear to me because I'm yet to learn js
31st Aug 2020, 7:06 AM
DN Josh
DN Josh - avatar
+ 1
Josh, I don't think there is anyway to handle scroll events without JS. you should learn JS Basics before trying something like this. scroll events: https://developer.mozilla.org/en-US/docs/Web/API/Document/scroll_event
31st Aug 2020, 7:10 AM
Raj Chhatrala
Raj Chhatrala - avatar