I am looking to create a header that changes based on the scroll event, similar to how it works on this website. When the cursor is at the top of the page, the header will have one appearance, and as you scroll down, the header content will change and become fixed.
While I have come across examples that shrink and fix headers, none of them address the issue of changing header content like I desire.
Note: Ideally, I would prefer a solution that does not involve third-party packages, as they tend to slow down page loading with multiple JavaScript files.
Thank you
- Sticky header on scroll with jQuery and CSS
- Persistent Headers
FOR EXAMPLE:
window.onscroll=function ()
{
//Based on given offset, such as 100px maximum
if (scroll == down)
{
//Display header_2 as fixed header
}
else
{
//Display header_1 as fixed header
}
}
<div class="container">
<div id="header_1">BIG HEADER with no menu</header>
<div id="header_2">SMALL HEADER with menu only</header>
</div>