کدهارو طبق فیلم آموزشی زدم
کدهای HTML :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="container">
<div id="myanimate"></div>
</div>
<button onclick="move()">animator</button>
<style>
#container{
width:500px;
height:500px;
position:relative;
background-color:yellow
}
#myanimate{
width: 50px;
height: 50px;
position: absolute;
background-color: red;}
</style>
<script src="main.js"></script>
</body>
</html>
کد های JAVASCRIPT :
function move(){
var animator=document.getElementById("myanimate");
var start = 0;
var animate = setInterval(go,5);
function go(){
if(start==450){
clearInterval(animate);
}
else{
start++;
animator.style.top = start;}
}
}از واحد px استفاده کنید
animator.style.top = start+"px";