请帮我看看这个定时器用的有什么问题
我想让背景颜色进行渐变,这个代码写完后DIV的背景色一下就变了,没有出现渐变的效果
请帮我看看是哪里出的问题?
setTimeout定时器的函数语句用不用加 ' ' (引号)呀? ColorFlash函数里的setTimeout定时器要是加引号就不执行,要是不加背景虽然变色,但是没有渐变的效果。
<html>
<head>
<meta charset='utf-8'/>
<title></title>
<style>
#block{
width:400px;
}
</style>
<script>
function catchEvent(eventObj,evnt,eventHandler){
if(eventObj.addEventListener)
{
eventObj.addEventListener(evnt,eventHandler,false);
}
else if(eventObj.attachEvent)
{
evnt='on'+evnt;
eventObj.attachEvent(evnt,eventHandler);
}
}
catchEvent(window,'load',setupping);
function setupping(){
document.getElementById('block').style.background='#ffffff';
setTimeout('ColorFlash(255)',2000);
}
function ColorFlash(newColor){
var hexVal=newColor.toString(16);
if(hexVal.length<02){
hexVal='0'+hexVal;
}
var colorString='#ffff'+hexVal;
var blockDiv=document.getElementById('block');
blockDiv.style.background=colorString;
if(newColor>0){
newColor=newColor-5;
setTimeout(ColorFlash(newColor),1550);
}
}
</script>
</head>
<body>
<div id="block">
<h1>Hello</h1>
</div>
</body>
</html>