琴& 2019-01-16 16:03 采纳率: 50%
浏览 288
已采纳

【多个运动】函数哪里错了?

<!DOCTYPE html>
<html lang="en">
<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>
    div {
        width: 100px;
        height: 50px;
        background-color: red;
        margin-top:50px;
    } 
    </style>
        <script type="text/javascript">                                        
        window.onload=function()
        {
            var aDiv = document.getElementsByTagName('div');

            for(let i=0;i<aDiv.length;i++)
            {
                aDiv[i].timer = null;
                aDiv[i].onmouseover = function ()
                {
                    startMove(this,300);
                }
                aDiv[i].onmouseout = function ()
                {
                    startMove(this,100);
                }
            }
        }

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

                    if(obj.offsetWidth == iTarget)
                    {
                        clearInterval(obj.timer);
                    }
                    else
                    {
                        obj.style.width = obj.offsetWidth + iSpeed + 'px';
                    }
                },30)
        }
    </script>
</head>
<body>
    <div></div>
    <div></div>
    <div></div>        
</body>
</html>
  • 写回答

3条回答 默认 最新

  • 琴& 2019-01-16 16:28
    关注
    obj.timer=setInterval(function(){},30)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog