requestanimationframe

Solutions on MaxInterview for requestanimationframe by the best coders in the world

showing results for - "requestanimationframe"
Amira
27 Jan 2016
1function animateFunction()
2{
3	//animate stuff
4    window.requestAnimationFrame(animateFunction);
5}
6window.requestAnimationFrame(animateFunction);
Joaquín
29 Aug 2017
1/* Request Animation Frame By Gourav Khurana */
2
3
4https://flaviocopes.com/requestanimationframe/
5https://glitch.com/edit/#!/flavio-requestanimationframe-example?path=script.js%3A1%3A0
6https://glitch.com/edit/#!/flavio-settimeout-animation?path=script.js%3A54%3A4
Giulia
03 Jul 2019
1const element = document.getElementById('some-element-you-want-to-animate');
2let start, previousTimeStamp;
3
4function step(timestamp) {
5  if (start === undefined)
6    start = timestamp;
7  const elapsed = timestamp - start;
8
9  if (previousTimeStamp !== timestamp) {
10    // Math.min() is used here to make sure the element stops at exactly 200px
11    const count = Math.min(0.1 * elapsed, 200);
12    element.style.transform = 'translateX(' + count + 'px)';
13  }
14
15  if (elapsed < 2000) { // Stop the animation after 2 seconds
16    previousTimeStamp = timestamp
17    window.requestAnimationFrame(step);
18  }
19}
20
21window.requestAnimationFrame(step);
Ginnie
23 Jan 2017
1/* Tells the browser that you wish to perform an animation and 
2 requests that the browser call a specified function 
3 to update an animation before the next repaint. */
4
5requestAnimationFrame(() => {
6    // some animation-related/dependent code here
7});
8
9/* The callback function is automatically passed a timestamp 
10 indicating the precise time requestAnimationFrame() was called at.
11 requestAnimationFrame() returns a non-zero integer that can be passed into 
12 cancelAnimationFrame() to cancel a requestAnimationFrame() call */
13
14/* Advantages over setTimeout(..., 1000/60) approach:
15 - The browser can optimize it, so animations will be smoother
16 - Animations in inactive tabs will stop, allowing the CPU to chill
17 - More battery-friendly */
18
19
20
21
queries leading to this page
js requestanimationframe examplerequestanimationframe in javascriptwhat does requestanimationframe do three jshtml requestanimationframe 27requestanimationframe 27requestanimationframewhat is requestanimationframewindow requestanimationframe 28 29requestframeanimation examplerequestanimationframe jsopposite of requestanimationframejavascript request frame animationwindow requestanimationframemethod requestanimationframe 28 29 requestanimationframe 28move 29requestanimation framethis within requestanimationframerequestanimationframe anddocument requestanimationframerequestanimationframe typerequestanimationframe dtwhy requestanimationframe is bettermodify requestanimationframewhat does requestanimationframe dorequestanimationframe w3mdn requestanimationframerequestanimationframe with timees6 requestanimationframerequestanimationframe javascriptwhat is requestanimationframe in javascriptrequestanimationframe in javascript infowhen should i use requestanimationframewindow requestanimationframejavascript requestanimationframerequestanimationframe this in callbackrequestanimationframe durationrequestanimationframe 28 29requestanimationframe nodejsshould i use requestanimationframerequestanimationframe of window requestanimationframehow to use requestanimationframehow to use requestanimationframe in an objectjs requestanimationframe 3fhow does requestanimationframe workrequestanimationframe frameraterequestanimationframe 28updatecanvas 29js requestanimationframerequestanimationframe examplerequestanimationframe problemrequestanimationframe mdnhow to use requestanimationframe in javascriptjavascript sto requestanimationframerequestanimationframe in jsrequestanimationframe vs settimourequestanimationframe