运行下面的代码,大神们看看哪里错了,为什么透明度总是最后变成0?
<!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>透明度</title>
<style>
div{
width:200px;
height:200px;
background:#F00;
opacity:1;
}
</style>
<script>
window.onload=function(){
var div=document.getElementsByTagName('div')[0];
div.onmouseover=function(){
biantmd();
}
}
var tmd=1;
var timer=null;
function biantmd(){
var div=document.getElementsByTagName('div')[0];
clearInterval(timer);
timer=setInterval(function(){
if(tmd==0.3){
clearInterval(timer);
}else{
tmd=tmd-0.1;
div.style.opacity=tmd;
}
//clearInterval(timer);
},30);
}
</script>
</head>
<body>
<div></div>
</body>
</html>