多物体的练市反应怎么做?
多物体的练市反应怎么做?
<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
*{
margin: 0px;
padding: 0px;
}
ul,li{
list-style: none;
}
ul li{
width: 200px;
height: 100px;
background: yellow;
margin-bottom: 20px;
filter:alpha(opacity:30);
opacity:0.3;
}
</style>
<script type="text/javascript">
var timer;
window.onload = function(){
var square = document.getElementsByTagName("li");
for(var i = 0;i<square.length;i++){
square[i].timer = null;
square[i].onmouseover = function(){
startMove(this,"width",400,function(){
startMove(this,"height",200);
});
//startMove(this,"opacity",100);
}
square[i].onmouseout = function(){
startMove(this,"width",200,function(){
startMove(this,"height",100);
});
//startMove(this,"opacity",30);
}
}
/*
//单物体的链式反应
var li = document.getElementById("li1");
li.timer = null;
li.onmouseover = function(){
startMove(li,"width",400,function(){
startMove(li,"height",200);
})
}
li.onmouseout = function(){
startMove(li,"width",200,function(){
startMove(li,"height",100);
})
}*/
}
//var timer = null;
function startMove(obj,attr,target,fn){
clearInterval(obj.timer);
obj.timer = setInterval(function(){
//var icur = parseInt(getStyle(obj,attr));
var icur = 0;
if(attr == "opacity"){
icur = Math.round(parseFloat(getStyle(obj,attr))*100);
}else{
icur = parseInt(getStyle(obj,attr));
}
var speed = (target-icur)/8;
speed = speed>0?Math.ceil(speed):Math.floor(speed);
if(icur == target){
clearInterval(obj.timer);
if(fn){
fn();
}
}else{
if(attr == "opacity"){
obj.style.filter = "alpha(opacity:'+(icur+speed)+')";
obj.style.opacity = (icur + speed)/100;
}else{
obj.style[attr] = icur+speed+"px";
}
//obj.style[attr] = icur+speed+"px";
}
},30)
}
function getStyle(obj,attr){
if(obj.currentStyle){
return obj.currentStyle[attr];
}else{
return getComputedStyle(obj,false)[attr];
}
}
</script>
</head>
<body>
<ul>
<li id="li1"></li>
<li></li>
<li></li>
</ul>
</body>
</html>
报错,链式反应中的参数this应该是有问题的,应该怎么写?