问答详情
源自:2-1 JS速度动画

实现不了,各位大神给看看哪里有问题?

<!doctype html>
<html>
 <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <title>滑出导航栏</title>
  <style>
body,div,span{
    margin: 0;
    padding: 0;
}
#div1{
    width: 200px;
    height: 200px;
    background: red;
    position: relative;
    left:-200px;
    top:200px;
}
#div1 span{
        width: 20px;
        height: 50px;
        background: blue;
        position: absolute;
        left: 200px;
        top:75px;
    }

  </style>
 
  <script>
    window.onload=function(){
        var v=document.getELementById("div1");
        v.onmouseover=function(){
            star();
        v.onmouseout=function(){
            star1();
        }    
        }
    }
        var timer=null;
    function star(){
        clearInterval(timer);
        var v=document.getELementById("div1");
        timer=setInterval(function(){
            if(v.offsetLeft==0){
                clearInterval(timer);
            }
            else{
                v.style.left=v.offsetLeft+10+"px";
            }
        },30)
    }
    function star1(){
        clearInterval(timer);
        var v=document.getELementById("div1");
        timer=setInterval(function(){
            if(v.offsetLeft==-200){
                clearInterval(timer);
            }
            else{
                v.style.left=v.offsetLeft-10+"px";
            }
        },30)
    }
</script>  
  <body>
<div id="div1">
<span id="share">分享</span>
</div>
  </body>
  </html>


提问者:名字只是个代号丶 2016-08-02 19:27

个回答

  • hey_whatsup
    2016-08-02 22:26:39
    已采纳

    两个错误

    1.

    window.onload=function(){


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


            v.onmouseover=function(){


                star();
             }


            v.onmouseout=function(){

         star1()

       }

    括号问题

    2.

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

    中的是getElementByld()不是getELementByld();

     l不是L


  • 丶过河卒
    2016-08-02 22:31:59

    首先32,43,55行的document.getElementById(),有问题是ElementById(),L不要大写还有第34行star();后面少个中括号,38行的中括号去掉,这是两个事件。

  • Millerwang47
    2016-08-02 22:30:00

    是你的document.getEL(这里错了。)ementById("div1");

    应该是document.getElementById("div1");

    L 大小写的问题。  仔细啊。

    推荐你用chrome浏览器。它的检查功能很棒。

    加油!