JSFiddle - React, Tailwind, and code Playground

HTML

<div id="scroll"></div> <!-- force a scrollbar -->
<div id="log">The user is at the top</div> <!-- log the results -->

CSS

#scroll {
    height: 1000px;
}

#log {
    position: fixed;
    top: 0;
    left: 0;
}

JavaScript

function getScrollTop(){
    if(typeof pageYOffset!= 'undefined'){
        //most browsers
        return pageYOffset;
    }
    else{
        var B= document.body; //IE 'quirks'
        var D= document.documentElement; //IE with doctype
        D= (D.clientHeight)? D: B;
        return D.scrollTop;
    }
}

var log = document.getElementById('log'); // just for logging the current state

setInterval(function(){
    if(!getScrollTop()) log.innerHTML = 'The user is at the top';
    else log.innerHTML = 'The user is not at the top';
}, 1000); // checks every second if the user is at the top