请问我的为什么实现不了?
<!Doctype html>
<html>
<head>
<meta charset="utf-8">
<title>js透明度变化</title>
<style>
div{width:200px;height:200px;background:#0f0;opacity:0.2;}
</style>
</head>
<body>
<script>
var newdiv=document.createElement("div");
document.body.appendChild(newdiv);
var timer=null;
newdiv.onmouseover=function(){
fadeToogle(1);
}
newdiv.onmouseout=function(){
fadeToogle(0.2);
}
function fadeToogle(iTarget){
if(timer){
clearInterval(timer);
}
timer=setInterval(function(){
var speed;
if(newdiv.style.opacity>iTarget){
speed=-0.05;
}
if(newdiv.style.opacity<iTarget){
speed=0.05;
}
if(newdiv.style.opacity==iTarget){
clearInterval(timer);
}else{
newdiv.style.opacity+=speed;
}
},30)
}
</script>
</body>
</html>