为什么js的currentStyle没有奏效呢?

</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说未定义是怎么回事呢?谢谢大神的指导?

阅读 3.1k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题