Capturing the “scroll down” event?

后端 未结 10 2218
闹比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 13:12

    /**
     * This function will determine if a client mousewheel is scrolling up or down.
     */
      //window.addEventListener("load", eScroll);
    
      function eScroll() {
    
          window.addEventListener('mousewheel', (event)=> {
    
            let originalEvent = event.wheelDeltaY;
    
            if (event.wheelDeltaY >= 0) {
                console.log('Scroll up');
            }
            else {
                console.log('Scroll down');
            }
        });
      }
    
      window.addEventListener("load", scrollDown);
    
      function scrollDown() {
    
          window.addEventListener('mousewheel', (event)=> {
    
         if (event.wheelDeltaY <= 0) {
            console.log(event.wheelDeltaY);
            console.log('Mousewheel has scrolled down');
          }
       })
      }
    
      window.addEventListener("load", scrollUp);
    
      function scrollUp() {
    
          window.addEventListener('mousewheel', (event)=> {
    
          if (event.wheelDeltaY > 0) {
            console.log(event.wheelDeltaY);
            console.log('Mousewheel has scrolled up');
          }
      })
    
      }
    

提交回复
热议问题