综合了透明和多物体运动效果但是还是有点问题能帮我看一下吗?
<title>多物体运动</title>
<style>
body,ul,li{
padding:0;
margin:0;
}
ul,li{
list-style:none;
}
ul li{
width:200px;
height:100px;
background:#FF0;
margin-bottom:20px;
filter:alpha(opacity:30);
opacity:0.3;
}
</style>
<script>
window.onload= function(){
var aLi= document.getElementsByTagName('li');
for(var i=0;i<aLi.length;i++){
aLi[i].timer=null;
aLi[i].alpha=30;
aLi[i].onmouseover=function(){
startMove(this,400,100)
}
aLi[i].onmouseout=function(){
startMove(this,200,30)
}
}
}
//var timer=null;
function startMove(obj,iTarget,style){
clearInterval(obj.timer);
obj.timer=setInterval(function(){
var speed = (iTarget-obj.offsetWidth)/8;
speed = speed>0?Math.ceil(speed):Math.floor(speed);
if(obj.offsetWidth == iTarget){
clearInterval(obj.timer);
}
else{
obj.style.width = obj.offsetWidth+speed+'px';
}
var app = 0;
if(obj.alpha>style){
app = -10;
}
else{
app = 10;
}
if(obj.alpha == style){
clearInterval(obj.timer)
}
else{
obj.alpha+=app;
obj.style.opacity = obj.alpha/100
}
},30);
}
</script>
</head>
<body>
<ul>
<li></li>
<li></li>
<li></li>
</ul>
</body>
</html>
物体的长度还是有问题,鼠标碰了过后有的会变长