JSFiddle - React, Tailwind, and code Playground

HTML

<div class="top">We have reached the first element</div>
<div class="one"></div>
<div class="two"></div>
<div class="three"></div>

CSS

.top {
    position: fixed;
    left: 0px;
    top: 0px;
    width: 100%;
    text-align: center;
    padding: 10px 0px;
    background: rgba(255,255,255,0.3);
}
.one, .two, .three {
    width: 100%;
    height: 1000px;
}
.one {
    background: red;
}

.two {
    background: blue;
}

.three {
    background: green;
}
.active {
    background: red;
}

JavaScript

$(window).scroll(function(){
    var one = $('.one'),
        two = $('.two'),
        three = $('.three'),
        top = $('.top'),
        scrollPos = $('body').scrollTop();
        
    if (scrollPos >= one.position().top && scrollPos <= one.position().top + parseInt(one.height())) {
        top.html('We have reached the first element');
    } else if (scrollPos >= two.position().top && scrollPos <= two.position().top + parseInt(two.height())) {
        top.html('We have reached the second element');
    } else if (scrollPos >= three.position().top && scrollPos <= three.position().top + parseInt(one.height())) {
        top.html('We have reached the third element');
    } 
});