Created
November 12, 2020 00:49
-
-
Save mrmemmo/0104fa2c0babce1ebfca194c4a37e15d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<style> | |
#container { | |
width: 400px; | |
height: 400px; | |
position: relative; | |
background: yellow; | |
} | |
#animate { | |
width: 50px; | |
height: 50px; | |
position: absolute; | |
background-color: red; | |
} | |
</style> | |
<body> | |
<p><button onclick="myMove()">Click Me</button></p> | |
<div id ="container"> | |
<div id ="animate">hello</div> | |
</div> | |
<script> | |
function myMove() { | |
var elem = document.getElementById("animate"); | |
var pos = 0; | |
var 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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment