Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript scroll function

// Binding an event to scroll will cause that event to be fired excessively.
// Tie your event to a throttle instead to preserve smooth scrolling:
window.addEventListener('scroll', throttle(myFunction, 1000)) // Fire myFunction when you scroll/are scrolling, but only every 1000ms.

function myFunction() { // The main function you want fired by scrolling.
	console.log('hello')
}


// Utility functions
function throttle(goal_func, wait_ms) { // fires goal_func but only if wait_ms has elapsed, otherwise does nothing.
  var time = Date.now()
  return function() {
    if ((time + wait_ms - Date.now()) < 0) {
      goal_func()
      time = Date.now()
    }
  }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: html add new line in js alert 
Javascript :: js select disabled 
Javascript :: check if variable is undefined or null jquery 
Javascript :: disable text selection in js 
Javascript :: js alert 
Javascript :: set a previous year to the current date in javascript 
Javascript :: VM724:1 Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0 
Javascript :: settimeout 
Javascript :: javascript password validation regex test 
Javascript :: check box all in jequery data table 
Javascript :: javascript substring after character 
Javascript :: javascript date minus minutes 
Javascript :: modify margin top javascript 
Javascript :: js decrement for loop 
Javascript :: javascript round number to nearest 5 
Javascript :: remove white space from string in js 
Javascript :: Node Sass could not find a binding for your current environment 
Javascript :: make image circle css react 
Javascript :: sort array by date 
Javascript :: how to set height of material ui dialog react 
Javascript :: ng new module w route 
Javascript :: js read date from milliseconds 
Javascript :: javascript falsy values 
Javascript :: react js empty build 
Javascript :: moment date is in range 
Javascript :: ffmpeg convert mp4 to avi 
Javascript :: get child eleemtn by native element angular 
Javascript :: change value of key in array of objects javascript 
Javascript :: eof while parsing 
Javascript :: convert class object to json node js 
ADD CONTENT
Topic
Content
Source link
Name
1+1 =