Javascript detect browser scroll to the top?

后端 未结 5 1541

How do I modify the following code to detect scrolling to the top page instead.

window.onscroll = function(ev) {
    if ((window.innerHeight + window.scroll         


        
5条回答
  •  一整个雨季
    2020-12-11 17:29

    if (document.body.scrollTop == 0 || document.documentElement.scrollTop == 0) 
    {
        alert("top");
    }
    

    worked for me

    https://www.w3schools.com/jsref/event_onscroll.asp

提交回复
热议问题