This is pretty much my first attempt at this, I was wondering, can anyone tell me why this doesn't work?
I put an alert("lol") in both to test and only the start function is being called, the second isn't.
[code]
<script type="text/javascript">
var x = 0;
var y = 0;
var mx= 0;
var my= 0;
function start()
{
var mx= document.getElementById('calculat').style.left
var my= document.getElementById('calculat').style.top
circlemove(1);
}
function circlemove(angle)
{
angle+=0.1;
if (angle > 2 * Math.PI)
{
angle=0;
}
x = 300 * cos(angle);
y = 300 * sin(angle);
document.getElementById('calculat').style.left = mx + x;
document.getElementById('calculat').style.top = my + y;
setTimeout("circlemove('angle')",100);
}
</script>
[/code]
-snippedy snip-
[QUOTE=borisjake;25995183]This is pretty much my first attempt at this, I was wondering, can anyone tell me why this doesn't work?
I put an alert("lol") in both to test and only the start function is being called, the second isn't.
[code]
<script type="text/javascript">
var x = 0;
var y = 0;
var mx= 0;
var my= 0;
function start()
{
var mx= document.getElementById('calculat').style.left
var my= document.getElementById('calculat').style.top
circlemove(1);
}
function circlemove(angle)
{
angle+=0.1;
if (angle > 2 * Math.PI)
{
angle=0;
}
x = 300 * cos(angle);
y = 300 * sin(angle);
document.getElementById('calculat').style.left = mx + x;
document.getElementById('calculat').style.top = my + y;
setTimeout("circlemove('angle')",100);
}
</script>
[/code][/QUOTE]
Set the Div position to absolute.
[QUOTE=borisjake;25995183]This is pretty much my first attempt at this, I was wondering, can anyone tell me why this doesn't work?
I put an alert("lol") in both to test and only the start function is being called, the second isn't.
[code]
<script type="text/javascript">
var x = 0;
var y = 0;
var mx= 0;
var my= 0;
function start()
{
var mx= document.getElementById('calculat').style.left
var my= document.getElementById('calculat').style.top
circlemove(1);
}
function circlemove(angle)
{
angle+=0.1;
if (angle > 2 * Math.PI)
{
angle=0;
}
x = 300 * cos(angle);
y = 300 * sin(angle);
document.getElementById('calculat').style.left = mx + x;
document.getElementById('calculat').style.top = my + y;
setTimeout("circlemove('angle')",100);
}
</script>
[/code][/QUOTE]
cos() and sin() are part of the method Math, so you'll need to use Math.sin() and Math.cos() instead.
[QUOTE=deadeye536;26069949]cos() and sin() are part of the method Math, so you'll need to use Math.sin() and Math.cos() instead.[/QUOTE]
:lol:
cos and sin are methods of the object Math
[QUOTE=Siemens;26075030]:lol:
cos and sin are methods of the object Math[/QUOTE]
Gah, why I shouldn't post on just a few hours of sleep in the dead of night... Still, got the point across to use Math.sin() and Math.cos() instead.
plus you need parseInt() because the left and top have px on the end of the number
Sorry, you need to Log In to post a reply to this thread.