Capturing the “scroll down” event?

后端 未结 10 2085
闹比i
闹比i 2020-12-28 12:17

I\'m designing a very simple web page (HTML only), the only \"feature\" I want to implement is to do something when the user scrolls down the page, is there a way to capture

10条回答
  •  孤城傲影
    2020-12-28 12:53

    above answers are correct. Here's the vanilla Javascript approach.

    document.addEventListener("mousewheel", function(event){
      if(event.wheelDelta >= 0){
        console.log("up")
      }else{
        console.log("down")
      }
    })
    
    

提交回复
热议问题