Advertisement
1xptolevitico69

RequestAnimationFrame

May 27th, 2019
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 0.63 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title></title>
  5. <meta charset="UTF-8">
  6. <meta name="viewport" content="width=device-width">
  7. <style>
  8. img {   width:250px;margin:200px auto;display:block;
  9.           border:5px solid red;padding:5px;    }
  10. </style>
  11. </head>
  12. <body>
  13.  
  14. <img id='image' onclick='spin()' src='https://images.pexels.com/photos/416160/pexels-photo-416160.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500'/>
  15.  
  16. <script>
  17. i=0;
  18.  
  19. function spin(){
  20. x = requestAnimationFrame(spin);      //   60 frames per second ( 60fps )
  21. i++;
  22. image.style.transform='rotate('+i+'deg)';
  23. if(i==360){cancelAnimationFrame(x);}
  24. }
  25.  
  26. </script>
  27. </body>
  28. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement