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

来源:2-1 JS速度动画

名字只是个代号丶

2016-08-02 19:27

<!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>


写回答 关注

3回答

  • 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-03 08:15:39

    共 1 条回复 >

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

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

    丶过河卒

    说错了,是花括号“{”。

    2016-08-02 22:33:45

    共 1 条回复 >

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

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

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

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

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

    加油!

    Miller... 回复名字只是个代...

    不好意思啊,才看到...就是在网页中右键点击你要检查的元素,出现的菜单最后一个就是检查功能。

    2016-09-08 20:23:45

    共 2 条回复 >

JS动画效果

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

113931 学习 · 1443 问题

查看课程

相似问题