JSFiddle - React, Tailwind, and code Playground
by Kriem
HTML
<div style='height:200px;' class='post'>One date</div>
<div style='height:250px;' class='post'>Another date</div>
<div style='height:350px;' class='post'>And another date</div>
<div style='height:200px;' class='post'>And one more date</div>
<div id='date'></div>
<div style='height:800px;'></div>
CSS
.post {border: 1px dashed grey; margin-right: 50px; margin-bottom: 20px;}
#date {position:fixed; top:10px; right:0px; height: 90px; width: 45px; background: grey;}
JavaScript
$(window).on("scroll resize", function(){
var pos=$('#date').offset();
$('.post').each(function(){
if(pos.top >= $(this).offset().top && pos.top <= $(this).next().offset().top)
{
$('#date').html($(this).html()); //or any other way you want to get the date
return; //break the loop
}
});
});
$(document).ready(function(){
$(window).trigger('scroll'); // init the value
});