Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

JavaScript animations

<!DOCTYPE html>
<html>
<style>
#container {
  width: 400px;
  height: 400px;
  border-radius: 10%;
  position: relative;
  background: rgb(130, 240, 231);
}
#animate {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  border: 3px solid rgb(218, 15, 15);
  position: absolute;
  background-color: rgb(51, 255, 0);
}
</style>
<body>

<p><button onclick="myMove()">Click Me</button></p> 

<div id ="container">
  <div id ="animate"><br><p>(★‿★)</p></div>
  <br><br>
  <br><p>hello from mohammad alshraideh</p>
</div>

<script>
function myMove() {
  let id = null;
  const elem = document.getElementById("animate");   
  let pos = 0;
  clearInterval(id);
  id = setInterval(frame, 5);
  function frame() {
    if (pos == 350) {
      clearInterval(id);
    } else {
      pos++; 
      elem.style.top = pos + "px"; 
      elem.style.left = pos + "px"; 
    }
  }
}
</script>

</body>
</html>
 
PREVIOUS NEXT
Tagged: #JavaScript #animations
ADD COMMENT
Topic
Name
4+4 =