看了又看还是没发现哪里错了,透明度没反应
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>透明度</title>
<style type="text/css">
*{margin:0;padding: 0;}
#div1{
float:left;
margin:10px;
background: red;
height:200px;
width:200px;
left:0px;
top:80px;
opacity:0.3;
filter:alpha(opacity:30);//IE
}
</style>
<script type="text/javascript">
window.onload=function(){
var oDiv=document.getElementsByTagName('div1');
for(var i=0;i<oDiv.length;i++){
oDiv[i].alpha=30;
oDiv[i].onmouseover=function(){
startmove(this,100);
}
oDiv[i].onmouseout=function(){
startmove(this,30);
}
}
}
//var timer=null;
//var alpha=30; 多个物体是不能使用公共样式,需要对每一个对象都定义
var speed=0;
function startmove(obj,goal){
//var oDiv=document.getElementsByTagName('div1');
clearInterval(obj.timer);
obj.timer=setInterval(function(){
if(obj.alpha==goal){ //判断加在定时器里面
clearInterval(obj.timer);
}
else{
if(goal>obj.alpha){
speed=3;
}
else{speed=-3;}
obj.alpha+=speed;
obj.style.opacity=obj.alpha/100;
obj.style.filter='alpha(opacity:'+obj.alpha+')';//IE
}
},30)
}
</script>
</head>
<body>
<div id="div1"></div>
<div id="div1"></div>
<div id="div1"></div>
</body>
</html>