这个怎么不动的?

来源:2-1 JS速度动画

吴思超0

2015-12-10 12:03

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<title>练习JS</title>

</head>

<style type="text/css">

body{

margin:0;

padding:0;

}

.div1{

width:200px;

height:140px;

background-color: red;

left: -202px;

    position: relative;

}

.div1 span{

width:20px;

    height: 50px;

    background: #eee;

    position: absolute;

    left: 200px;

    top:75px;

}

</style>

<body>

<div class="div1">

<span id="share">分享</span>

</div>

<script>

window.onload = function(){

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

wsc.onmouseover = function(){

startMove();

}

}

function startMove(){

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

setInterval(function(){

wsc.style.left = wsc.offsetLeft+10+'px';

},30)

}

</script>

</body>

</html>


写回答 关注

2回答

  • 李晓健
    2015-12-10 12:23:20
    已采纳
    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8">
        <title>练习JS</title>
    </head>
    <style type="text/css">
        body{
            margin:0;
            padding:0;
        }
        #div1{
            width:200px;
            height:140px;
            background-color: red;
            left: -202px;
            position: relative;
        }
        #div1 span{
            width:20px;
            height: 50px;
            background: #eee;
            position: absolute;
            left: 200px;
            top:75px;
        }
    </style>
    <body>
    <div id="div1">
        <span id="share">分享</span>
    </div>
    <script>
        window.onload = function(){
            var wsc = document.getElementById('div1');
            wsc.onmouseover = function(){
                startMove();
            }
        }
        function startMove(){
            var wsc = document.getElementById('div1');
            setInterval(function(){
                wsc.style.left = wsc.offsetLeft+10+'px';
            },30)
        }
    </script>
    </body>
    </html>

    你上面写的class  你下面用getElementById 去取,肯定取不到呀

    吴思超0

    非常感谢!

    2015-12-10 14:13:21

    共 1 条回复 >

  • 吴思超0
    2015-12-10 12:52:07

    原来是getElementById只能获取ID类的。谢谢了

JS动画效果

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

113923 学习 · 1443 问题

查看课程

相似问题