JSFiddle - React, Tailwind, and code Playground

by Jeremi Liwanag

HTML

<div class="admin">asdasd</div>
<div class="a">asdasd</div>
<div class="b">
    <div>fixed at the top when scrolled down</div>
</div>
<div class="c">blue box will stay on top when 'reach this class' reaches the top</div>

CSS

.admin {
    height: 50px;
    background: black;
    width: 500px;
}
.a {
    height: 200px;
    background-color:red;
    width: 500px;
}
.b {
    height: 100px;
    background-color:blue;
    width: 500px;
    position:relative;
}
.c {
    height: 2000px;
    background-color:pink;
    width: 500px;
}

JavaScript

jQuery(function ($) {
    var distance = $('.c').offset().top,
        $window = $(window);

    $window.scroll(function () {
        if ($window.scrollTop() >= distance) {
            $(".b").css({
                position: 'fixed',
                top: '0'
            });
        } else {
            $(".b").css({
                position: 'inherit',
                top: '10'
            });
        }
    });
});