和老師的代碼幾乎一樣,為什么我的不能縮回來?
<!DOCTYPE html>
<html>
<head>
? <meta charset="utf-8">
? <title>多物體運動</title>
? <style type="text/css">
? ?
? ? li{height: 150px;width:150px;background: #ccc;margin:30px;list-style: none;}
? </style>
? <script type="text/javascript">
? window.onload=function(){
? var aLi=document.getElementsByTagName("li")
? for(var i=0;i<aLi.length;i++){
? aLi[i].timer=null;
? aLi[i].onmouseover=function() {
? moveFun(this,400);
? }
? aLi[i].onmouseout=function() {
? // body...
? moveFun(this,400);
? }
? }
? ?
? }
? function moveFun(obj,iTarget){
?
? 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';
? }
?
? },30)
? }
? </script>
</head>
<body>
<ul>
<li></li>
<li></li>
<li></li>
</ul>
</body>
</html>>
2016-10-19
? aLi[i].onmouseout=function() {
? // body...
? moveFun(this,400);
?因為你鼠標移出的時候目標值還是400,移入的時候已經(jīng)達到400了,當然移出的時候不會變了