JSFiddle - React, Tailwind, and code Playground

by jaibuu

HTML

<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<div id="content">
    <div class="masthead"></div>
    <div class="menu"></div>
    <div style="height:2280px;"></div>
</div>

CSS

* {
    margin: 0;
    padding: 0;
}
div.masthead {
    height: 480px;
    background: #333;
}
div.menu {
    height: 64px;
    background: #ff0000;
}
div.menu.fixed {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
}
div.sticky {
    position: -webkit-sticky;
    position: -moz-sticky;
    position: -ms-sticky;
    position: -o-sticky;
    position: sticky;
    top: 0;
    left: 0;
    right: 0;
}
html,body,#content {
    width:100%;
    height:100%;
}
#content {
    background-color: lightblue;
    overflow:scroll;
}

JavaScript

var mastheadHeight = $('.masthead').height(),
    menu = $('.menu');


function checkScrolling() {

    if ($('#content').scrollTop() > mastheadHeight) {
        menu.addClass('fixed');
    } else {
        menu.removeClass('fixed');
    }

}

$('#content').scroll(function () {
    checkScrolling();
});