I have the following code:
The purpose is: What I mouse over on any of the two <div> , I want the background to fade out. The way it is now, it stucks after the first call to "doLighten()". It is only being executed once. Can anyone tell me why?
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<style type="text/css">
.style1{
background:#000000;
}
</style>
<script type="text/javascript">
var originalColor = 0;
function RGBtoHex(R,G,B) {
return toHex(R)+toHex(G)+toHex(B)
}
function toHex(N) {
if (N==null)
return "00";
N=parseInt(N);
if (N==0 || isNaN(N))
return "00";
N=Math.max(0,N);
N=Math.min(N,255);
N=Math.round(N);
return "0123456789ABCDEF".charAt((N-N%16)/16) + "0123456789ABCDEF".charAt(N%16);
}
function doLighten(obj){
originalColor = originalColor - 20;
txt.value = originalColor;
obj.style.background = '#' + RGBtoHex(originalColor,originalColor,originalColor);
if(originalColor < 255){
setTimeout("doLighten(obj)", 30);
}
else
originalColor = 0;
}
function lighten(obj){
originalColor = 255;
obj.style.background = RGBtoHex(originalColor,originalColor,originalColor);
doLighten(obj);
}
</script>
</head>
<body>
<div class="style1" onmouseover="lighten(this)" >what the...!</div>
<p></p>
<div class="style1" onmouseover="lighten(this)" >what the...!</div>
<textarea id="txt"> </textarea>
</body>
</html>
The purpose is: What I mouse over on any of the two <div> , I want the background to fade out. The way it is now, it stucks after the first call to "doLighten()". It is only being executed once. Can anyone tell me why?