JSFiddle - React, Tailwind, and code Playground
HTML
<div id="foo">
</div>
<div id="nav">
</div>
<div id="bar">
</div>
CSS
#foo{
height:100px;
width:100%;
}
#bar{
height:1000px;
width:100%;
}
#nav{
width: 80%;
height: 100px;
margin: 0 auto;
background-color: #FFCC00;
}
.fixed-nav{
position: fixed;
top: 0;
}
JavaScript
var bottom = $('#nav').offset().top;
$(window).scroll(function(){
if ($(this).scrollTop() > bottom){
$('#nav').addClass('fixed-nav');
}
else{
$('#nav').removeClass('fixed-nav');
}
});