4fit?
02-07-2007, 02:01 PM
I'm working on a required project for a scripting course I am currently taking. I am supposed to write a script that will cause a button to move around the screen when the user tries to click on it. The example in the book shows this huge drawn out array of left and top positions. I did this a totally different way by generating random numbers to use for the positions. This works perfectly in FireFox and Netscape, but does not work in IE.
So, I put it in DreamWeaver and ran a browser check on it and the only error that came back was on the onmouseover event of the button. Does anyone know a way to make this work in IE? Thanks in advance for any help you can provide!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Moving Button</title>
<style type="text/css">
.btnmove {
position:absolute;
left:5px;
top:50px;
width:75px;
}
</style>
<script type="text/javascript">
<!--
//fuction to create a random rounded number between a determined
//start and end number
function rand(start, end) {
return Math.round(Math.random()*(end-start)) + start;
}
//variables for left and top attributes of the button
var l = 0, t = 0
//the button move function
function buttonMove() {
//get the button
var button = document.getElementById("button");
//generate random number to use for left style
if (l <= (window.innerWidth / 2))
l = (rand((window.innerWidth / 2), (window.innerWidth)-75));
else
l = (rand(5, (window.innerWidth / 2)));
//apply left style
button.style.left = l + "px";
//generate random number to use for top style
if (t <= (window.innerHeight / 2))
t = (rand((window.innerHeight / 2), (window.innerHeight)-25));
else
t = (rand(50, (window.innerHeight / 2)));
//apply top style
button.style.top = t + "px";
}
-->
</script>
</head>
<body>
<h2>Catch Me If You Can!!!</h2>
<input onmouseover="buttonMove();" class="btnmove" id="button"
name="mover" value="Click Me!" type="button">
</body>
</html>
So, I put it in DreamWeaver and ran a browser check on it and the only error that came back was on the onmouseover event of the button. Does anyone know a way to make this work in IE? Thanks in advance for any help you can provide!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Moving Button</title>
<style type="text/css">
.btnmove {
position:absolute;
left:5px;
top:50px;
width:75px;
}
</style>
<script type="text/javascript">
<!--
//fuction to create a random rounded number between a determined
//start and end number
function rand(start, end) {
return Math.round(Math.random()*(end-start)) + start;
}
//variables for left and top attributes of the button
var l = 0, t = 0
//the button move function
function buttonMove() {
//get the button
var button = document.getElementById("button");
//generate random number to use for left style
if (l <= (window.innerWidth / 2))
l = (rand((window.innerWidth / 2), (window.innerWidth)-75));
else
l = (rand(5, (window.innerWidth / 2)));
//apply left style
button.style.left = l + "px";
//generate random number to use for top style
if (t <= (window.innerHeight / 2))
t = (rand((window.innerHeight / 2), (window.innerHeight)-25));
else
t = (rand(50, (window.innerHeight / 2)));
//apply top style
button.style.top = t + "px";
}
-->
</script>
</head>
<body>
<h2>Catch Me If You Can!!!</h2>
<input onmouseover="buttonMove();" class="btnmove" id="button"
name="mover" value="Click Me!" type="button">
</body>
</html>