为什么跟老师敲的一毛一样 但我的运行不了啊???

来源:4-3 任意属性值(一)

Mr_国产青年Javency

2017-02-28 23:35

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>任意属性值(一)</title>
</head>
<style>
    *{margin: 0;padding: 0}
    ul li{
        list-style: none;
    }
    li{
        width: 200px;
        height: 100px;
        background: yellow;
        margin-bottom: 10px;
        border: 5px solid #000;
    }
</style>
<script>
    window.onload=function(){
        var Li1=document.getElementById("li1");
        var Li2=document.getElementById("li2");
        Li1.onmouseover=function(){
            startMove(this,"height",400);
        }
        Li1.onmouseout=function(){
            startMove(this,"height",100);
        }
        Li2.onmouseover=function(){
            startMove(this,"width",400);
        }
        Li2.onmouseout=function(){
            startMove(this,"width",200);
        }
    }
    function getStyle(obj,attr){
        if(obj.currentStyle){
            return obj.currentStyle[attr];
        }
        else{
            return getComputedStyle(obj,false)[attr];
        }
    }
    function startMove(obj,attr,iTarget){
        clearInterval(obj.timer);
        obj.timer=setInterval(function(){
            var icur=parseInt(getStyle(obj.attr));
            var speed=(iTarget-icur)/8;
            speed=speed>0?Math.ceil(speed):Math.floor(speed);
            if(icur==iTarget){
                clearInterval(obj.timer);
            }
            else{
                obj.style[attr]=icur+speed+"px";
            }
        },30);
    }
</script>
<body>
<ul>
    <li id="li1"></li>
    <li id="li2"></li>
</ul>
</body>
</html>


写回答 关注

1回答

  • Mr_国产青年Javency
    2017-03-01 15:42:16

    我自己找到了 第48行应该是逗号

JS动画效果

通过本课程JS动画的学习,从简单动画开始,逐步深入各种动画框架封装

113925 学习 · 1443 问题

查看课程

相似问题