...

View Full Version : MoveBy, MoveTo



TNO
10-19-2005, 03:40 PM
I am testing a couple functions but am having trouble with one:


<html>
<head>
<script src="js/animation.js" type="text/javascript" defer></script>
</head>
<body>
<span style="background-color:blue;position:absolute;top:10;left:10" id="Actor">Actor</span>
<div style="position:absolute;top:80%;left:1%;background-color:gray;width:100%;font-weight:bold;">
<hr>
Move By:<input type="text" size="3" id="MBX" value="X" onclick="this.value=''">
&nbsp<input size="3" type="text" value="Y" id="MBY" onclick="this.value=''">
&nbsp&nbsp<button onclick="MoveBy(document.getElementById('Actor'),document.getElementById('MBX').value,document.getElementById ('MBY').value)">Go</button>
<br>
Move To:<input type="text" size="3" id="MTX" value="X" onclick="this.value=''">
&nbsp<input size="3" type="text" value="Y" id="MTY" onclick="this.value=''">
&nbsp&nbsp<button onclick="MoveTo(document.getElementById('Actor'),document.getElementById('MTX').value,document.getElementById ('MTY').value)">Go</button>
<hr>
</div>
</body>
</html>

the .js:


function MoveBy(obj,x,y)
{
if (parseInt(navigator.appVersion) >= 5 || navigator.appVersion.indexOf["MSIE 5"] != -1)
{
obj.style.left = x + obj.style.left;
obj.style.top = y + obj.style.top;
}
}

function MoveTo(obj,x,y)
{
if (parseInt(navigator.appVersion) >= 5 || navigator.appVersion.indexOf["MSIE 5"] != -1)
{
obj.style.position = "absolute";
var units = (MoveTo.arguments.length > 3) ? MoveTo.arguments[3] : "px";
obj.style.left = x + units;
obj.style.top = y + units;
}
}

There must be something wrong with my logic. MoveTo works properly, but MoveBy seems to grow exponentially each time.

TNO
10-19-2005, 04:12 PM
Nevermind.....

the function was treating the values as strings:

X + obj.style.left

parseInt(X) + parseInt(obj.style.left)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum