I'm trying to move a div on a semi circular path. I have tried the parametric equation and it works.
I don't know why using for loops makes my program to stop working. When I try to move it using a for loop, The browser stops working and the memory usage skyrockets.
I don't know what is the problem. Please Advise.
<html>
<head>
<title>movediv</title>
<style type="text/css">
.bodycss {
background-color: aqua ;
}
.posmove{
position: absolute;
background-color: blue;
width: 20px;
height: 20px;
}
.buttonpos{
position: absolute;
top:250px;
left:250px;
background-color: "green";
}
</style>
<script type="text/javascript">
var i=0,j=0;
var x = 100;
function movediv()
{
for(i=250-x;i<251+x;i++)
{
j = 250 + Math.floor(Math.sqrt((x*x) - (i-250)*(i-250)));
setTimeout(function()
{
document.getElementById('point').style.top = j + "px";
document.getElementById('point').style.left = i + "px";
}, 100);
if(i==250+x) i=250-x;
}
}
</script>
</head>
<body class="bodycss">
<div class="posmove" id="point"></div>
<form>
<input type="button" id="radius" class="buttonpos" onclick="movediv();" >
</form>
</body>
</html>