为了账号安全,请及时绑定邮箱和手机立即绑定

为什么我的代码就是实现不了多物体运动?请大神看看。

<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Document</title>
<style type="text/css">
ul ,li{

    list-style: none;
}
ul li{
width:200px;
height: 100px;
background: yellow;
margin-bottom: 20px;

}


</style>
<script type="text/javascript">
    window.onload=function(){
    var Ali=document.getElementsByTagName("li");
    for(var i=0;i<Ali.length;i++){
       Ali[i].onmouseover=function(){
        startMove(this,400);

       }

       Ali[i].onmouseout=function(){
           startMove(this,200);
       }
    }


    }

var timer=null;
function startMove(obj,iTarget){
clearInterval(timer);
timer=setInterval(function(){
    var speed=(iTarget-obj.offsetwidth)/8;
    speed=speed>0?Math.ceil(speed):Math.floor(speed);
    if(obj.offsetwidth=iTarget){
     clearInterval(timer);

    }
    else{
        obj.style.width=obj.offsetwidth+speed+'px';
    }


},30)


}

</script>

</head>




<body>
    <ul>
        <li></li>
        <li></li>
        <li></li>



    </ul>
</body>
</html>

正在回答

2 回答

   var speed=(iTarget-obj.offsetwidth)/8;

为什么要除以8的


0 回复 有任何疑惑可以回复我~

不好意思重复了,已经解决


0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

为什么我的代码就是实现不了多物体运动?请大神看看。

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信