troy1984
10-29-2003, 03:46 PM
Hi all,
Im having trouble with a javascript;
I want an image inside of a div move from point to point. This works... only i dont want the layer to move diagonally across the page. The layer must only move horizontally and vertically.
This is my code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<div id="ball" style="position:absolute;"><img src="ball.gif"></div>
<a href="java script: moveit(400, 100)">About</a> <a href="java script: moveit(500, 100)">news</a> <a href="java script: moveit(610, 100)">Sitemap</a> <a href="java script: moveit(720, 100)">Contact</a>
<br> <a href="java script: moveit(140, 192)">Why ADF</a>
<script language="JavaScript" type="text/javascript">
step = 1;
startX = 100;
startY = 200;
currentX = startX;
currentY = startY;
function initialize()
{
//Start positions
document.getElementById("ball").style.left = startX;
document.getElementById("ball").style.top = startY;
}
function moveit(x, y)
{
if (currentX < x)
{
document.getElementById("ball").style.left = currentX + step;
currentX = currentX + step;
}
if (currentX > x)
{
document.getElementById("ball").style.left = currentX - step;
currentX = currentX - step;
}
//-----
if (currentY < y)
{
document.getElementById("ball").style.top = currentY + step;
currentY = currentY + step;
}
if (currentY > y)
{
document.getElementById("ball").style.top = currentY - step;
currentY = currentY - step;
}
if ( (currentX != x) || (currentY != y)) setTimeout("moveit("+x+","+y+")",1);
}
initialize();
</script>
</body>
</html>
Thank you everyone.
Greetings,
Troy
(I've uploaded my script on www.trespassersw.nl/scm ... I want the ball to slide over the darblue line)
Im having trouble with a javascript;
I want an image inside of a div move from point to point. This works... only i dont want the layer to move diagonally across the page. The layer must only move horizontally and vertically.
This is my code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<div id="ball" style="position:absolute;"><img src="ball.gif"></div>
<a href="java script: moveit(400, 100)">About</a> <a href="java script: moveit(500, 100)">news</a> <a href="java script: moveit(610, 100)">Sitemap</a> <a href="java script: moveit(720, 100)">Contact</a>
<br> <a href="java script: moveit(140, 192)">Why ADF</a>
<script language="JavaScript" type="text/javascript">
step = 1;
startX = 100;
startY = 200;
currentX = startX;
currentY = startY;
function initialize()
{
//Start positions
document.getElementById("ball").style.left = startX;
document.getElementById("ball").style.top = startY;
}
function moveit(x, y)
{
if (currentX < x)
{
document.getElementById("ball").style.left = currentX + step;
currentX = currentX + step;
}
if (currentX > x)
{
document.getElementById("ball").style.left = currentX - step;
currentX = currentX - step;
}
//-----
if (currentY < y)
{
document.getElementById("ball").style.top = currentY + step;
currentY = currentY + step;
}
if (currentY > y)
{
document.getElementById("ball").style.top = currentY - step;
currentY = currentY - step;
}
if ( (currentX != x) || (currentY != y)) setTimeout("moveit("+x+","+y+")",1);
}
initialize();
</script>
</body>
</html>
Thank you everyone.
Greetings,
Troy
(I've uploaded my script on www.trespassersw.nl/scm ... I want the ball to slide over the darblue line)