Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

scroll down up js

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 if number is integer js 
Javascript :: datatable cdn 
Javascript :: how to get date using tolocaledatestring 
Javascript :: how to use compare password in node js 
Javascript :: uppercase in word javascript 
Javascript :: angular call function every x seconds 
Javascript :: jquery toggle input checkbox 
Javascript :: find string in array javascript 
Javascript :: javascript convert minutes to hh mm 
Javascript :: js dynamicly add script 
Javascript :: use thymeleaf variable in javascript 
Javascript :: get largest number in array javascript 
Javascript :: Add event listener for loop 
Javascript :: cypress have attribute 
Javascript :: javascript ascending and descending 
Javascript :: run function every second javascript 
Javascript :: FullScreen Image By OnClick Jquery 
Javascript :: laravel csrf token ajax post 
Javascript :: load +main.js with system.import 
Javascript :: javascript get child element by class 
Javascript :: string repeat codewars javascript 
Javascript :: redux append to an array 
Javascript :: javascript go to div id 
Javascript :: do you need a semicolon in javascript 
Javascript :: ytdl-core 
Javascript :: how to install mongodb in node js 
Javascript :: set variable to object without editing old object js 
Javascript :: fibonacci javascript 
Javascript :: array of refs react 
Javascript :: how to check if function is running js 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =