PDA

View Full Version : random direction



mikemay
10-31-2004, 08:32 PM
Hi everybody I am triyin to move a image in random direction when click on any help would be great thanks



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script type="text/javascript">
function moveaway(){m=0;
e=document.getElementById("image");
if(h>700){h=h-50;m=1;}
if(h<50){h=h+50;m=1;}
if(v>350){v=v-50;m=1;}
if(v<50){v=v+50;m=1;}
if(!m){n=Math.random()*100-50;o=Math.random()*100-50;h=h+n;v=v+o;}
e.style.left = h + 'px';
e.style.top = v + 'px';
}
</script>
<style type="text/css">
#image {
position:relative;
width: 225px;
height: 148px;
float: left;
margin: 5px;
}
</style>

</head>
<body>
<img src="xlionsideways.jpg" alt="lion" id="image"/>
</body>
</html> :D :D

Willy Duitt
11-02-2004, 12:09 AM
Not sure that I understand what you are trying to do here...

But h and v are undefined....

Try turning on IE javascript error notification under Tools --> Internet Options --> Advanced

Or try using Mozilla's Javascript Console so that you can be alerted to the errors which are bing thrown...

.....Willy