Advertisement
Guest User

Untitled

a guest
Oct 25th, 2019
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <style>
  5. #element {
  6. position: relative;
  7. cursor: pointer;
  8. top: 50px;
  9. right: 450px;
  10. }
  11. html, body {
  12. height: 100%;
  13. margin: 0;
  14. }
  15.  
  16. body {
  17. background: gray;
  18. display: flex;
  19. align-items: center;
  20. justify-content: center;
  21. overflow-y: hidden;
  22. }
  23. canvas {
  24. background: url('background.jpg');
  25. border: 1px solid white;
  26. }
  27. </style>
  28. </head>
  29.  
  30. <body>
  31. <canvas height="336" width="638"></canvas>
  32. <img width="300" height="300" id="element" src="element.png">
  33.  
  34. <button id="move">Movement</button>
  35.  
  36. <script>
  37. move.onclick = function() {
  38. let start = Date.now();
  39.  
  40. let timer = setInterval(function() {
  41. let timePassed = Date.now() - start;
  42.  
  43. element.style.right = timePassed / 5 + 'px';
  44.  
  45. if (timePassed > 2000) clearInterval(timer);
  46.  
  47. }, 20);
  48. }
  49. </script>
  50.  
  51.  
  52. </body>
  53.  
  54. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement