这段代码是鼠标放在模块上透明度会改变,鼠标移除透明度会变回默认值,但是我怎么调透明度都不变,求高手指点……
<!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>
*{margin:0;padding:0;}
ul,li{list-style: none;
}
ul li{
width:200px;
height:200px;
background:#666;
margin: 10px;
float: left;
opacity: 0.3;
}
</style>
<script type="text/javascript">
window.onload=function(){
var oLi=document.getElementsByTagName('li');
for (var i = 0;i<oLi.length;i++){
oLi[i].alpha=30;
oLi[i].timer=null;
oLi[i].onmouseover=function(){
startMove(this,100);
}
oLi[i].onmouseout=function(){
startMove(this,30);
}
}
}
//var alpha=30;
//var timer=null;
function startMove(obj,iwidth){
clearInterval(obj.timer);
//var oLi=document.getElementsByTagName('li');
obj.timer=setInterval(function(){
var speed=0;
if (iwidth>obj.alpha) {
speed=10;
}else{
speed=-10;
};
if (obj.alpha==iwidth) {
clearInterval(obj.timer);
}else{
obj.alpha=obj.alpha+speed+"px";
obj.style.opacity=obj.alpha/100;
}
},30)
}
</script>
</head>
<body>
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</body>
</html>
懒人一只
相关分类