I want to dedect if the user scrolls to the top of a webpage when he is already on the top. This means that normal scrolling shouldn't trigger a action, just if the scrollbar is on the top and the user scrolls further to the top it does something.
I have tried with the code below, but it triggers when the user arrives on top and not when he "overscroll" it. Here is the jsfiddle.
window.onscroll = function(ev) {
if ((window.innerHeight + window.scrollY) ==window.innerHeight) {
alert("The action");
}
document.getElementById('a').innerHTML= window.scrollY+";"+window.innerHeight+";"+(window.innerHeight+ + window.scrollY);
};
p{
position: fixed;
}
<br>
<br><br>
<br>
<p id="a">sdf
</p>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>