这个变化函数哪里出问题了?

<!DOCTYPE html>

<html>

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <meta http-equiv="X-UA-Compatible" content="ie=edge">

    <title>多物体运动框架</title>

    <style>

    #div1 {

        width: 100px;

        height: 50px;

        background-color: red;

        margin-top:50px;

    } 

    </style>

        <script type="text/javascript">                                        

        window.onload=function()

        {

            var oDiv = document.getElementById('div1');


            oDiv.onmouseover=function()

            {

                startMove(300);

            }

            oDiv.onmouseout=function()

            {

                startMove(100);

            }    

        }


        var timer = null;


        function startMove(iTarget)//这个函数

        {

                var oDiv = document.getElementById('div1');


                clearInterval(timer);

                timer=setInterval(function () {

                    var iSpeed = (iTarget - oDiv.offsetwidth)/8;

                    iSpeed=iSpeed>0?Math.ceil(iSpeed):Math.floor(iSpeed);


                    if(oDiv.offsetWidth == iTarget)

                    {

                        clearInterval(timer);

                    }

                    else

                    {

                        oDiv.style.width = oDiv.offsetWidth + iSpeed + 'px';

                    }

                },30)

        }

        </script>

</head>

<body>

    <div id="div1"></div>

</body>

</html>


慕妹3146593
浏览 376回答 2
2回答

慕后森

var iSpeed = (iTarget - oDiv.offsetwidth)/8;这一行 那个 offsetWidthw没有大写

收到一只叮咚

F12 设置断点 调试你就知道
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript