JSFiddle - React, Tailwind, and code Playground

by glee

HTML

Some content.<br/>
Glee is awesome!<br/>
Glee is awesome!<br/>
Glee is awesome!<br/>
Glee is awesome!<br/>
Glee is awesome!<br/>
Glee is awesome!<br/>
<br/>
<div class = "box">Scroll past me! Glee is awesome!</div>

CSS

body {
    height: 1500px;
}
.box {
    background-color: rgb(0, 162, 232);
    width: 150px;
    height: 150px;
    color: white;
}

JavaScript

var oritop = -100;
$(window).scroll(function() {
    var scrollt = window.scrollY;
    var elm = $(".box");
    if(oritop < 0) {
        oritop= elm.offset().top;
    }
    if(scrollt >= oritop) {
        elm.css({"position": "fixed", "top": 0, "left": 0});
    }
    else {
        elm.css("position", "static");
    }
});