运行下面的代码,大神们看看哪里错了,为什么透明度总是最后变成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];
var tmd;
var timer=null;
div.onmouseover=function(){
biantmd();
}
function biantmd(){
tmd=1;
clearInterval(timer);
timer=setInterval(function(){
if(tmd==0.3){
clearInterval(timer);
}else{
tmd=tmd-0.01;
div.style.opacity=tmd;
}
//clearInterval(timer);
},300);
}
}
</script>
</head>
<body>
<div></div>
</body>
</html>