Facebook
From AlexEremenko, 4 Years ago, written in JavaScript.
This paste is a reply to AnimationJS from AlexEremenko - view diff
Embed
Download Paste or View Raw
Hits: 178
  1. <!DOCTYPE html>
  2. <html lang="ru">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <title>Title</title>
  6.     <link rel="stylesheet" href="main.css">
  7. </head>
  8. <body>
  9.     <div class="ground">
  10.         <div class="ball" id="ball">
  11.         </div>
  12.     </div>
  13.  
  14.     <input type="text" class="x">
  15.  
  16.     <script>
  17.         let ball = document.querySelector('.ball');
  18.         ball.onclick = function() {
  19.             let start = Date.now();
  20.  
  21.             let timer = setInterval(function() {
  22.                 let x = document.querySelector('.x');
  23.                 let xValue = x.value + 'px';
  24.                 let timePassed = Date.now() - start;
  25.  
  26.                 ball.style.left = timePassed / 5 + 'px';
  27.  
  28.                 if (ball.style.left > xValue) clearInterval(timer);
  29.  
  30.             }, 20);
  31.         }
  32.     </script>
  33. </body>
  34. </html>