.nav-header2{
background: purple;
display: flex;
justify-content: center;
align-items: center;
}
.header2-container{
width: 68vw;
height: 60px;
padding: 0 2vh;
border: 1px solid red;
border-radius: 0.5rem;
display: flex;
justify-content: space-between;
align-items: center;
}
.nav-header1{
background: lightblue;
display: flex;
justify-content: center;
align-items: center;
}
.header1-container{
width: 68vw;
height: 60px;
padding: 0 2vh;
border: 1px solid blue;
border-radius: 0.5rem;
display: flex;
justify-content: space-between;
align-items: center;
}
<!--header2 -->
<nav class="nav-header2">
<div class="header2-container">
<h1>header2<h2>
</div>
</nav>
<!-- header1 -->
<nav class="nav-header1">
<div class="header1-container">
<h1>header1<h2>
</div>
</nav>
I have two different headers set up for my website which are named as header1 and header2.
The task I want to achieve is displaying header2 when the user scrolls down more than 60 pixels, and hiding it when scrolling back up within less than 60 pixels.
If the condition is met (scrolling down more than 60px), then display header2, otherwise keep displaying header1.
I've made numerous attempts to accomplish this but haven't been successful. Please lend me your assistance. Thank you very much!