Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Scroll event throttling JS MDN

// Reference: http://www.html5rocks.com/en/tutorials/speed/animations/

let lastKnownScrollPosition = 0;
let ticking = false;

function doSomething(scrollPos) {
  // Do something with the scroll position
}

document.addEventListener('scroll', function(e) {
  lastKnownScrollPosition = window.scrollY;

  if (!ticking) {
    window.requestAnimationFrame(function() {
      doSomething(lastKnownScrollPosition);
      ticking = false;
    });

    ticking = true;
  }
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: discord.js v12 to v13 
Javascript :: append to a div and save the previous data after refresh page in javascript 
Javascript :: react native navigation export 
Javascript :: jquery ui music player 
Javascript :: function directory javascript 
Javascript :: array of function 
Javascript :: jasmine returnvalues example 
Javascript :: “javascript sleep 1 second” is a pretty common code problem that people search ;-) 
Javascript :: TextInputEditText click event 
Javascript :: sentry not working in frontend 
Javascript :: see wss request on network tab 
Javascript :: change class on resize window jquery 
Javascript :: nodejs post req accept form data 
Javascript :: filter state based on text field react 
Javascript :: threejs check if camera is pointing towards object 
Javascript :: react hook for component size 
Javascript :: regex match caret 
Javascript :: mindate from another datepicker 
Javascript :: Multiline string in ES6 
Javascript :: pass props to svg 
Javascript :: url is not a constructor javascript 
Javascript :: loader on map function in react js 
Javascript :: javascrpt 
Javascript :: react native delay input 
Javascript :: hide fill apexcharts 
Javascript :: Functions & Exec Context makePlans 
Javascript :: react Alert when rate changes 
Javascript :: return axios response from seperate file 
Javascript :: como fazer um array em javascript stackoverflow 
Javascript :: cantsee auto complete for node jsmodules in vs code 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =