Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

setTimeout vs requestAnimationFrame

// setTimeout:
// 	Calls a function or evaluates an expression after a specified number of milliseconds.
// 	Doesn't mean that the function will be called after the exactly specified interval.
//	Can cause a browser to miss the frame.
// requestAnimationFrame
//	Works similarly to setTimeout 
//	called right before the next repaint in the browser occurs.

const timestamp = setTimeout(() => {...}); // runs as frequently as possible
const requestId = requestAnimationFrame(() => {...}); // runs once per frame

clearTimeout(timestamp); // clear previously added timeout
cancelAnimationFrame(requestId); // cancel an animation frame request 
Comment

PREVIOUS NEXT
Code Example
Javascript :: MongoNotConnectedError: Client must be connected before running operations 
Javascript :: how to remove comma from array in javascript 
Javascript :: javascript constructor and prototype 
Javascript :: font awesome react native icons 
Javascript :: javascript reset form 
Javascript :: deleting key of json object 
Javascript :: js page auto reload 
Javascript :: convert number to word js 
Javascript :: js includes 
Javascript :: jquery set input value 
Javascript :: how to remove a list of classes from an element using js 
Javascript :: javascript array add 
Javascript :: javascript get class name 
Javascript :: jquery in array 
Javascript :: filter javascript 
Javascript :: wait function in javascript 
Javascript :: JSON.parse() error handling 
Javascript :: find in array and change 
Javascript :: npm react dom routing 
Javascript :: import a script to my react componetn 
Javascript :: javascript cehck if array is empty 
Javascript :: javascript sort numbers 
Javascript :: Javascript form check to see if return or enter was pressed 
Javascript :: download json file react 
Javascript :: node mysql 
Javascript :: add parameter to url without reload jquery 
Javascript :: install latest electron 
Javascript :: node.js express post query string 
Javascript :: watch with multiple variables vuejs 
Javascript :: to uppercase js 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =