I'am trying to detect the scroll of a web page using JavaScript
I want to get an alert once only when the page is at top or not
var top = true;
$(window).on('scroll', function () {
if (window.scrollY > 0 && top==true) {
top = false;
alert("not top");
}else if (window.scrollY == 0 && top==false){
top = true;
alert("top");
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
The above code is not triggering alert at all !