JSFiddle - React, Tailwind, and code Playground

by Ketan Patel

HTML

<div class="content"></div>
<div class="fixme">Scroll here</div>

CSS

.content { height: 500px; }
.fixme { background: green; color: white; text-align: center; width: 100%; }

JavaScript

var fixmeTop = $('.fixme').offset().top;
$(window).scroll(function() {
    var currentScroll = $(window).scrollTop();
    if (currentScroll >= fixmeTop) {
        $('.fixme').css({
            position: 'fixed',
            top: '0',
            left: '0'
        });
    } else {
        $('.fixme').css({
            position: 'static'
        });
    }
});