Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

scroll down or up event listener

var lastScrollTop = 0;

// element should be replaced with the actual target element on which you have applied scroll, use window in case of no target element.
element.addEventListener("scroll", function(){ // or window.addEventListener("scroll"....
   var st = window.pageYOffset || document.documentElement.scrollTop; // Credits: "https://github.com/qeremy/so/blob/master/so.dom.js#L426"
   if (st > lastScrollTop){
      // downscroll code
   } else {
      // upscroll code
   }
   lastScrollTop = st <= 0 ? 0 : st; // For Mobile or negative scrolling
}, false);
Comment

javascript scroll up-down event

window.onwheel = e => {
  if(e.deltaY >= 0){
    // Scrolling Down with mouse
    console.log('Scroll Down');
  } else {
    // Scrolling Up with mouse
    console.log('Scroll Up');
  }
}
 Run code snippet
Comment

PREVIOUS NEXT
Code Example
Javascript :: check box jquery 
Javascript :: how to use infinite scroll in angular 
Javascript :: javascript hypot 
Javascript :: js addeventlistener foreach 
Javascript :: jsx style styling 
Javascript :: how to use js console log 
Javascript :: javascript nested functions 
Javascript :: vuejs router params 
Javascript :: change js 
Javascript :: change a variable outside a function js 
Javascript :: eventemitter in angular 
Javascript :: javascript fullscreen 
Javascript :: how to remove sub array null index in javascript 
Javascript :: javascript round to 7 decimal places 
Javascript :: vue loop 
Javascript :: innertext data form js 
Javascript :: node fs promises 
Javascript :: hourglasses js 
Javascript :: auto refresh page javascript 
Javascript :: my vscode does not recognize react code syntax 
Javascript :: javascript capitalize all letters 
Javascript :: Web Geolocation API 
Javascript :: react dom cdn 
Javascript :: match string in array javascript 
Javascript :: ** javascript 
Javascript :: javascript run function based on the page size 
Javascript :: google recaptcha reload 
Javascript :: upload files with angular 
Javascript :: usememo react 
Javascript :: some method in js 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =