改变透明度的代码,代码运行没反应
<!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 style="text/css">
*{padding:0;margin:0;}
div{width:150px;
margin-left:20px;
height:200px;
background:green;
filter:alpha(opacity:30);
opacity:0.3;
float: left;}
</style>
<script type="text/javascript">
window.onload=function(){
var adiv= document.getElementsByTagName("div");
for (var i=0;i<adiv.length;i++) {
adiv[i].alpha=30;
adiv[i].onmoseover=function(){startMove(this,100);}
adiv[i].onmouseout=function(){startMove(this,30);}
}
}
function startMove(obj,iTarget){
clearInterval(obj.timer);
obj.timer=setInterval(function(){
var speed=0
if(obj.alpha>iTarget){
speed = -10;
}
else{
speed = 10;
}
if(obj.alpha == iTarget) {
clearInterval(obj.timer);
}
else{obj.alpha+=speed;
obj.style.filter="alpha(opacity:"+obj.alpha+")";
obj.style.opacity=obj.alpha/100;}
},30)
}
</script>
</head>
<body>
<div></div>
<div></div>
<div></div>
<div></div>
</body>
</html>