ivana_andreevska

SetInterval and ClearInterval animating div element

Jan 18th, 2022
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <title>Title</title>
  6.     <link rel="stylesheet" href="jquery_ui.css">
  7.     <script src="jquery.js"></script>
  8.     <script src="jquery-ui.js"></script>
  9.     <style>
  10.         #moveMe {
  11.             position: absolute;
  12.         }
  13.     </style>
  14. </head>
  15. <body>
  16.  
  17. <button onclick="stop()">Stop!</button>
  18. <div id="moveMe">I am moving</div>
  19.  
  20.  
  21. <script>
  22.     var d = document.getElementById("moveMe")
  23.     var position = 0; //numeric value of where its going to be
  24.     var anime=setInterval(function () {
  25.         position += 1;
  26.         d.style.left = position + "px";
  27.         d.style.top = position + "px";
  28.         d.style.transform="rotate("+position+"deg)"
  29.     }, 10)
  30.     //run every second
  31.     // za da raboti i da se dvizi mora vo style na elementot koj se dvizi da mu dodaeme pozicija i da bide absolute
  32. function  stop()
  33. {
  34.     clearInterval(anime)
  35. }
  36.  
  37. </script>
  38.  
  39. </body>
  40. </html>
Advertisement
Add Comment
Please, Sign In to add comment