JSFiddle - React, Tailwind, and code Playground

by kougiland

HTML

<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<div>Whatever, content</div>
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>

CSS

div {
    position: relative;
    top: 0;
}

JavaScript

var standardPosition = $('div').offset().top;

$(window).scroll(function() {
    if ($(this).scrollTop() > standardPosition) $('div').css('position','fixed');
    else $('div').css('position','relative');
});