Answers for "css animation with javascript"

0

javascript css animation

Personally https://animejs.com/
Posted by: Guest on May-23-2021
1

css animation with javascript

<!DOCTYPE html>
<html>
<style>
#myContainer {
  width: 400px;
  height: 400px;
  position: relative;
  background: yellow;
}
#myAnimation {
  width: 50px;
  height: 50px;
  position: absolute;
  background-color: red;
}
</style>
<body>
<p>
<button onclick="myMove()">Click Me</button> 
</p>
<div id ="myContainer">
<div id ="myAnimation"></div>
</div>
<script>
var id = null;
function myMove() {
  var elem = document.getElementById("myAnimation");   
  var pos = 0;
  clearInterval(id);
  id = setInterval(frame, 10);
  function frame() {
    if (pos == 350) {
      clearInterval(id);
    } else {
      pos++; 
      elem.style.top = pos + 'px'; 
      elem.style.left = pos + 'px'; 
    }
  }
}
</script>
</body>
</html>
Posted by: Guest on July-29-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language