<!DOCTYPE?html>
<html>
<head>
<meta?charset="UTF-8">
<title>多物體運動</title>
<style>
*{margin:?0;padding:?0}
.li1{width:100px;height:100px;?margin-bottom:?50px;background-color:?teal;}
.li2{width:100px;height:100px;?margin-bottom:?50px;background-color:?teal;}
.li3{width:100px;height:100px;?margin-bottom:?50px;background-color:?teal;}
</style>
<script>
window.onload=function(){
var?lis=document.getElementsByTagName('li');
for(var?i=0;i<lis.length;i++){
lis[i].timer=null;
lis[i].onmouseover=go(this,400);
lis[i].onmouseout=go(this,100);
}
}
function?go(obj,target)
{
clearInterval(obj.timer);
obj.timer=setInterval(function(){
var?speed=(target-obj.offsetWidth)/30;
speed=speed<0?Math.floor(speed):Math.ceil(speed);
if(obj.offsetWidth==target){
clearInterval(obj.timer);
}
else{
obj.style.width=obj.offsetWidth+speed+'px';
}
},30);
}
</script>
</head>
<body>
<li></li>
<li></li>
<li></li>
</body>
</html>
簡單的動態(tài)伸縮為啥就是跑不起來呢?為什么瀏覽器工具會顯示obj.style.width錯誤
lulubiu
2017-05-03 16:36:18