The Hidden World of requestAnimationFrame

Поделиться
HTML-код
  • Опубликовано: 2 дек 2024

Комментарии • 63

  • @retagainez
    @retagainez 7 месяцев назад +2

    As chaotic as web development is, this has been a very straight-forward and useful resource for me to begin puzzling out how I could possibly start writing some 2-D physics engine in JavaScript.

  • @mykalimba
    @mykalimba 4 года назад +55

    For anyone wondering why most frames are spaced around 16.6 milliseconds apart, that is roughly equal to 60 FPS.

    • @Baargaa
      @Baargaa 3 года назад +12

      and if u wonder why there is 60FPS - it's coming from 60 Hz ;) - Refresh rate of monitors ;)

    • @techsyndrome3291
      @techsyndrome3291 2 года назад +7

      @@Baargaa nobody wondered that

    • @biswamohandwari780
      @biswamohandwari780 2 года назад +1

      really wonderful thank you

  • @maxtayebwa8987
    @maxtayebwa8987 4 года назад +28

    I dare anyone to tell me any better explanation for this thing! It's okay, youtube has billions of videos, feel free to try to tell me which channel even dares to compare!!
    Thanks prof, this was awesome, as usual of course!!!

    • @TheD2D21
      @TheD2D21 Год назад

      Well, you know, while the best explanaition I myself have come to so far as well, there is no video response feature anymore on RUclips for anybody to post a challenge to your dare.

  • @mrSargi7
    @mrSargi7 3 года назад +4

    This channel is my MDN on youtube, the best teacher with soothing voice and content that is always on point

  • @patils22
    @patils22 3 года назад +1

    Dodging the punch analogy !! It made the difference between setInterval and requestAnimationFrame crystal clear. Thanks.

  • @dajuanmcdonald3861
    @dajuanmcdonald3861 4 года назад +2

    This really helped me out with Cellular Automaton simulations and understanding exactly what double buffering is and how to do it.

  • @angladephil
    @angladephil 4 года назад +3

    Nice and useful ! I guess the CSS use this function behind the scenes for transitions.Thank you !

  • @Baargaa
    @Baargaa 3 года назад

    Thx! Good introduction to the topic. I just transormed my setInteval functions to requestAnimationFrame. Now all browsers has the same effect. Earlier animations on FF were little bit too lazy ;)

  • @mohammedhayari28
    @mohammedhayari28 3 года назад

    thank you so much from morocco for your easy explanation

  • @sleeplessdev7204
    @sleeplessdev7204 3 года назад +1

    I find that, oftentimes, when people try to name things to be more "friendly", it ends up making things more confusing.
    This was overall a great explanation though!

  • @smaragd_
    @smaragd_ 3 года назад

    Your voice is like political radio host. Which goes quite well with these teachings as well. Thanks for simple examples and hints. :)

  • @bisratiskool2193
    @bisratiskool2193 2 года назад +1

    I don't think requestAnimationFrame has ever been better explained

  • @maelstrom57
    @maelstrom57 3 года назад

    Finally an understandable explanation for this somewhat obscure method. Thanks a lot :)

  • @georgebockari289
    @georgebockari289 2 года назад

    I'm less than 3 minutes in and I'm going to sub. I can only imagine how you teach other topics, this was exceptional

  • @muegaschneemann
    @muegaschneemann 3 года назад

    YES, exactly what i was searching for!! Saved the vid!! Thanks a lot!

  • @saifeddine6479
    @saifeddine6479 3 года назад

    The way I explain things is just wonderful

  • @shankarghimire4492
    @shankarghimire4492 3 года назад

    Wow! wonderful explanation and demonstration! Best video I got so far! Thanks a lot!

  • @Giregar
    @Giregar 2 года назад

    Thanks you so much for this easy to understand introduction to Animation Frame.

  • @rajkiran4873
    @rajkiran4873 4 года назад

    Your explanation is simply awesome

  • @dejandjosic1258
    @dejandjosic1258 Год назад

    Very useful and well explained. Thanks!

  • @durgeshgupta6647
    @durgeshgupta6647 3 года назад

    awesome bro...clear explanation......from india

  • @arnav_0397
    @arnav_0397 3 года назад

    Amazing man, I just love the way you explain it,

  • @mouradelcadi
    @mouradelcadi 2 года назад

    Thanks for the beautiful video

  • @OmarOnAWave
    @OmarOnAWave 3 года назад

    Amazing explanation!!

  • @DanishKhan-lh3ob
    @DanishKhan-lh3ob 3 года назад

    Super Clean Explanation :)

  • @ryandsouza7100
    @ryandsouza7100 4 года назад +2

    Hi Steve. Great video as always. Just one question. For which use-cases do you think it would be best to use this as an alternative for CSS animation?

    • @suvendudas5391
      @suvendudas5391 4 года назад

      Same here

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  4 года назад +6

      When animating, stick to using transform and opacity as much as possible to get the best performance. Most things can be done in CSS but if you need to calculate position or property values then you will using JS. If you use JS then use requestAnimationFrame instead of setTimeout or setInterval.

    • @ryandsouza7100
      @ryandsouza7100 4 года назад

      @@SteveGriffith-Prof3ssorSt3v3 Cool. Noted. Thank you. 👍

  • @Jinxxeh
    @Jinxxeh Год назад

    Hi Steve, is there any benefit to wrapping something in window.requestAnimationFrame if you aren't repeatedly/recursively calling the callback? I've noticed people doing that sometimes and I'm not sure what the purpose is

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  Год назад +2

      It uses a different part of the event loop for scheduling things. So, if you need to have tasks, and microtasks and raf calls in a specific order, then it might be something you want.
      ruclips.net/video/w-jULX0D5cg/видео.html - video about the event loop etc.

  • @danielChibuogwu
    @danielChibuogwu 2 года назад

    Thank you for this video

  • @universalworthy2169
    @universalworthy2169 Год назад

    Hello Steve, thank you very much for your helpful video. I have a question: if I have multiple box elements and access them via an array const boxes = document.querySelectorAll(".box"); I would like to apply the box.style.transform ... for every item in the array when clicking with forEach, like boxes.forEach(item =>{item.addEventListener("click", ()=>handleClick()}
    ? I keep getting the error: Uncaught TypeError: Cannot set properties of undefined (setting 'transform'). I don't really understand this error. Please help. Thank you very much.

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  Год назад

      Whenever you see an error that say "Cannot" do something "of undefined (setting x)" It means that the thing you wrote in front of x is undefined. Usually a misspelled variable or missing variable or wrong scope of variable.

  • @stapler942
    @stapler942 3 года назад

    So I'm making a small grid-based game project in the JS canvas. I am needing a fixed time-step sort of mechanism for various updates. Would you say the easiest method is to call my draw() and update() functions after a certain count of frames in the requestAnimationFrame loop? Can I assume that this framerate will not be too different on different browsers/machines?

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  3 года назад +1

      The frame rate will definitely vary depending on the machine. But with requestAnimationFrame and highRes timestamps you can calculate things to run smoothly. You can also look at the Web Animations API.

  • @tails_the_god
    @tails_the_god 3 года назад

    Aw yes pretty smooth indeed.. I was getting smooth movements but now i get jerky movement in my windows programming when im programming my win32 NES emulator soooo it's about timing that causes it?

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  3 года назад

      Timing is a big part of it. You might find this interesting / helpful - ruclips.net/video/MCi6AZMkxcU/видео.html

  • @marcinkalmar9964
    @marcinkalmar9964 2 года назад

    Very good explanation , Sometimes i think that my sucess in programming dependence of teacher who teach me than of my brain capacity 😅

  • @abhim6380
    @abhim6380 4 года назад +1

    How do you change the speed of the animation?

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  4 года назад +1

      The function runs automatically each time the screen is being painted. Most of the time this should be a fairly stable time increment with smooth animations.
      You can use the time passed between frames or time passed since the page loaded to calculate things.

  • @Barnardrab
    @Barnardrab 3 года назад

    The motion still looks jittery, so it's not smooth. Is this the best we can get with JavaScript?

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  3 года назад +1

      Animation with JS is a complex topic with many layers, many techniques, and many approaches. requestAnimationFrame is just one tool in the toolbox. There are many factors that go into making animations run smoothly and many things that can interfere with that.

  • @suvendudas5391
    @suvendudas5391 4 года назад

    Thank you again.

  • @BrettCooper4702
    @BrettCooper4702 4 года назад

    Thanks, that was interesting.

  • @elkhanhamet2561
    @elkhanhamet2561 4 года назад

    thank you

  • @necronomicon-xmortis9362
    @necronomicon-xmortis9362 6 месяцев назад

    😢my numbers count but my box dont move 🤔🤷‍♂️

  • @allanimeworld2898
    @allanimeworld2898 3 года назад

    Sir i request to make a tut on making a finger swiper with vanilla js

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  3 года назад

      You can make tutorial requests in the comments here -
      But I have several videos about that already:
      ruclips.net/video/ga_SLzsUdTY/видео.html
      ruclips.net/video/rhqeN10bK10/видео.html
      ruclips.net/video/J06Uz7m-Jn8/видео.html

    • @allanimeworld2898
      @allanimeworld2898 3 года назад

      @@SteveGriffith-Prof3ssorSt3v3 yeah sir
      First thank you for reply
      You taught them i am talking about touch image slider.
      Then we will get how to use them.

  • @Ivan-dt9mc
    @Ivan-dt9mc 2 года назад

    thank you

  • @delcarmat
    @delcarmat 2 года назад

    thank you