How to pause animation in JS?

  • 0
    There is a code https://jsfiddle.net/hibinyen/549vkdhx/3/ - this is an animation of static pictures.

    Question 1. How can I pause this animation by clicking on the picture?

    Question 2. Why, when executing the loop several times, the animation accelerates, the further the faster

    Thanks in advance.

    PS. I'm not very good at JS :( I took the ready-made code and filed it for myself. I can't write something new
    JavaScript Joshua Norris, Apr 21, 2020

  • 2 Answers
  • 0
    function stopAnimation () {

    clearInterval (function);

    }

    And second, I don't even know how to solve
    Anonymous

  • 0
    To "stop" the value, write it to a variable that will allow you to start counting from the beginning. To be able to restore, write your interval into another variable and reset it on those events when you need it.



    To avoid speeding up, check if you have a dependency on an incremented value or a nested loop.
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!