Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How i can make onclick to start animation

I got requestAnimationFrame(loop); and I’m trying to make onclick button to start animation, once you press it animation starts, I got button figured out <button type="start" form="form1" value="start onclick="start()">start</button>
But i cannot figure out how to make it into a script.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Here is a snippet example :

<button onclick="start()">start</button>
<script>
   var animId=false;
   function start() {
      animId=requestAnimationFrame(loop);
   }
   function loop() {
      //your code here
   }
   // I added this in case you wanted to call a stop
   function stop() {
      animId && cancelAnimationFrame(animId);
   }
</script>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading