JSFiddle - React, Tailwind, and code Playground
HTML
<div class="nav" id="nav">
<nav>
<ul>
<li class="one"><a href="#one">One</a></li>
<li class="two"><a href="#two">Two</a></li>
<li class="three"><a href="#three">Three</a></li>
<li class="four"><a href="#four">Four</a></li>
</ul>
</nav>
</div>
<div id="one"></div>
CSS
* {
margin: 0;
padding: 0;
}
.nav {
position: fixed;
height: 40px;
background-color: black;
width: 100%;
}
.nav ul {
list-style-type: none;
}
.nav li {
position: fixed;
display: inline;
}
.nav a {
color: white;
}
#one {
height: 1500px;
width: 100%;
background-color: red;
}
.one {
margin-left: 30px;
}
.two {
margin-left: 90px;
}
.three {
margin-left: 130px;
}
.four {
margin-left: 190px;
}
JavaScript
$(document).ready(function(){
$(window).scroll(function() {
var $nav = $('#nav');
var st = $(this).scrollTop();
$nav.height( st );
if( st > 100 ) {
$nav.css("height", "100px");
} else if (st < 40) {
$nav.css("height", "40px");
}
})
})