账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    为什么js的currentStyle没有奏效呢?
    39
    0

    </html>### 为什么js的currentStyle没有奏效呢?

    相关代码

    // 请把代码文本粘贴到下方(请勿用图片代替代码)
    <!DOCTYPE html>
    <html lang="en">
    <head>

    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        div{width: 100px;height: 50px;background: yellow;margin: 10px;}
    </style>
    <script>
    
        window.onload=function () {
            var oDiv1 = document.getElementById('div1')
            var oDiv2 = document.getElementById('div2')
    
            oDiv1.onmouseover=function () {
                startMove(this,'width',400);
            }
            oDiv1.onmouseout=function () {
                startMove(this,'width',200);
            }
    
            oDiv2.onmouseover=function () {
                startMove(this,'height',200);
            }
            oDiv2.onmouseout=function () {
                startMove(this,'height',50);
            }
    
        }
    
        function getStyle(obj,name){
            if (obj.currentStyle) {
                return obj.currentStyle[name];
            }
           else {
                return getComputedStyle(obj,false)[name];
            }
        }
    
        function startMove(obj,hh,iTarget) {
            clearInterval(obj.timer);
            obj.timer=setInterval(function () {
                var speed=(iTarget-parseInt(getStyle(obj.hh)))/6;
                speed=speed>0?Math.ceil(speed):Math.floor(speed);
    
                if (parseInt(getStyle(obj.hh))==iTarget) {
                    clearInterval(obj.timer)
                }
                else {
                   obj.style[hh]=parseInt(getStyle(obj.hh))+speed+'px';
    
                }
            },300)
        }
    </script>

    </head>
    <body>
    <div id="div1"></div>
    <div id="div2"></div>

    </body>

    这个的currentStyle说未定义是怎么回事呢?谢谢大神的指导?

    0
    打赏
    收藏
    点击回答
        全部回答
    • 共 0 条
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部