requestAnimationFrame() - Beau teaches JavaScript

  Рет қаралды 50,561

freeCodeCamp.org

freeCodeCamp.org

Күн бұрын

The window.requestAnimationFrame() method tells the browser that you wish to perform an animation and requests that the browser call a specified function to update an animation before the next repaint.
💻 Code: codepen.io/bea...
🔗 More info: developer.mozi...
🐦 Beau Carnes on Twitter: / carnesbeau
⭐JavaScript Tutorials Playlists⭐
▶JavaScript Basics: • JavaScript Basics Course
▶Data Structures and Algorithms: • Data Structures and Al...
▶Design Patterns: • Design Patterns - Beau...
▶ES6: • ES6 - Beau teaches Jav...
▶Clean Code: • Clean Code - Beau teac...
-
We're busy people who learn to code, then practice by building projects for nonprofits. Learn Full-stack JavaScript, build a portfolio, and get great references with our open source community.
Join our community at freecodecamp.com
Read great tech articles at medium.freecod...

Пікірлер: 30
@ischysyt
@ischysyt 3 жыл бұрын
I watched this to understand how requestAnimationFrame works, now I need to find another PROPER video to understand.
@kostiantynkarzhanov9216
@kostiantynkarzhanov9216 2 жыл бұрын
thank you, Beau! It's a great lesson!
@CANIHAZURDREAMSPLS
@CANIHAZURDREAMSPLS 4 жыл бұрын
can you make a more clear video, bc I feel like this is a very important concept, and this video didn't do justice - PLEASE
@charlesbungabong3892
@charlesbungabong3892 3 жыл бұрын
beau teaches javascript, dude!
@CANIHAZURDREAMSPLS
@CANIHAZURDREAMSPLS 3 жыл бұрын
@@charlesbungabong3892 what...
@JulianHernandez-zw4ob
@JulianHernandez-zw4ob 3 жыл бұрын
I thought I was the only one who thought this video was terrible.
@vivekraj9875
@vivekraj9875 5 жыл бұрын
I can't understand timestamp😵
@rafadydkiemmacha7543
@rafadydkiemmacha7543 4 жыл бұрын
Timestamp in this case is just the amount of time that passed since you loaded your page. It’s useful, because keep in mind that animation engine doesn’t guarantee any stable progress. In theory, you can get 10 frames per second and then after a while it can go up 60. If you simply assume that 1 frame = 1 point in time, you may get your animation, game or whatever weird in pace. For example, your character can go slow for a few seconds and then go fast, just because your computer now is ready to render more frames per seconds, for any reason.
@1001-w5q
@1001-w5q 4 жыл бұрын
@@rafadydkiemmacha7543 I spent a while to understand how it works through playing around with different elements but then I saw your comment... Well, at least I got the answer on my own
@kubaissen
@kubaissen 7 жыл бұрын
No optimization? It's bad coding it supossed to be some like: function anim(timestamp) { window.requestAnimationFrame(anim); clear(); steps(actorList.steps); draws(actorList.draws); }
@airasyaqub4039
@airasyaqub4039 6 жыл бұрын
U didnt explain it good. U should shed some light on timestamp which is a very imp thing in rAF.
@arnobchowdhury9641
@arnobchowdhury9641 5 жыл бұрын
Right. I do not understand what timestamp is. Can you explain?
@sojumoscow
@sojumoscow 2 жыл бұрын
Yeah I have a hard time understanding it too. Its because thats not my native language I have to search every word lol
@raidoung4100
@raidoung4100 4 жыл бұрын
@freeCodeCamp perhaps it would be good to update this video ?:d The comments kind of indicate it would need some revision :d
@rajikkali2381
@rajikkali2381 2 жыл бұрын
Good planning, bad execution. I know what you're saying because I'm a coder, but otherwise I think I wouldn't have any idea. Speak in human terms, not technical ones.
@rafadydkiemmacha7543
@rafadydkiemmacha7543 4 жыл бұрын
It looks to me like you don’t fully understand how it works. What’s the point in cancelling animation like that? You say you cancel animation, but it’s not like that, because requestAnimationFrame() doesn’t work like interval. It works like a timeout! The cancelAnimationFrame() is almost never needed in practice. Instead, you would just check condition before running requestAnimationFrame() in your loop.
@dablo898
@dablo898 4 жыл бұрын
cancelAnimationFrame() is one of the advantages of using requestAnimationFrame over traditional statements it provides user full control over animation flow
@rafadydkiemmacha7543
@rafadydkiemmacha7543 4 жыл бұрын
Abid Ali he compares it to the interval, so it's pretty clean he doesn't understand how it works. Instead of cancelling the animation, the code would have been much more straightforward if he just used if() before calling requestAnimationFrame() each time. It's just one frame on animation, so the effect is pretty much identical.
@RFsalman
@RFsalman 4 жыл бұрын
i'm confused, it seems the requestAnimationFrame is still getting called even when the animation is over, so why is cancelAnimationFrame() almost never needed like you said ?
@rafadydkiemmacha7543
@rafadydkiemmacha7543 4 жыл бұрын
salmanrf requestAnimationFrame() works like setTimeout(), not setInterval(). It doesn't go on unless you explicitly request it.
@RFsalman
@RFsalman 4 жыл бұрын
@@rafadydkiemmacha7543 @Rafał Dydkiem Machał ohh !, i just realized, ever since i learned this function, i always reinvoke the rAF as the last statement in the animation function, separate from the test condition, so even the animation is finished the rAF is still getting called over and over again, lol, that is a ridiculous mistake from me, and you just made me realize it, thank you so much
@antwanwimberly1729
@antwanwimberly1729 10 ай бұрын
Bill Nyle the Seinfeld science guy Jerry 🤔 no soup for you The Yankees have been watching me since birth huh I know !! The Philließ
@BelminIbrahimovic-gh3xx
@BelminIbrahimovic-gh3xx 2 ай бұрын
Thats the most confusing example ive ever seen in my life
@antwanwimberly1729
@antwanwimberly1729 10 ай бұрын
Kylie Rose Jackson Junior On the tackle
@carlosbenavides670
@carlosbenavides670 3 жыл бұрын
Very poor explanation...
Animation in the DOM - Beau teaches JavaScript
7:40
freeCodeCamp.org
Рет қаралды 45 М.
THIS keyword - Beau teaches JavaScript
8:48
freeCodeCamp.org
Рет қаралды 58 М.
Worst flight ever
00:55
Adam W
Рет қаралды 34 МЛН
JavaScript Closures Tutorial (Explained in depth)
19:03
ColorCode
Рет қаралды 71 М.
You Are Using useEffect Wrong
14:40
Cosden Solutions
Рет қаралды 35 М.
The different types of JavaScript functions explained
14:47
Kevin Powell
Рет қаралды 42 М.
Test-Driven Development // Fun TDD Introduction with JavaScript
12:55
5 JavaScript Concepts You HAVE TO KNOW
9:38
James Q Quick
Рет қаралды 1,4 МЛН
DOM Nodes - Beau teaches JavaScript
5:05
freeCodeCamp.org
Рет қаралды 33 М.
Premature Optimization
12:39
CodeAesthetic
Рет қаралды 814 М.
The Hidden World of requestAnimationFrame
9:22
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 32 М.