JSFiddle - React, Tailwind, and code Playground
by b2550
HTML
<div id="contentSide">
<div id="contentSideIner">
</div>
</div>
CSS
body {
height: 4000px;
}
#contentSide {
background: black;
margin: 10px;
float: right;
width: 300px;
height: 4000px;
}
#contentSideIner {
width: 280px;
height: 400px;
margin: 0 auto;
background: red;
}
.sticky {
position: fixed;
top: 0;
}
JavaScript
var $window = $(window),
$sticky = $('#contentSideIner'),
elTop = $sticky.offset().top;
$window.scroll(function() {
$sticky.toggleClass('sticky', $window.scrollTop() > elTop);
});