码迷,mamicode.com
首页 > Web开发 > 详细

js运动 分享到

时间:2015-03-08 17:00:22      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:

<!doctype html>
<html>
    <head>
        <meta charset = "utf-8">
        <title>未命题</title>
        <style>
            *{margin: 0;
                padding: 0;
            }
            #div1{
                height: 200px;
                width: 150px;
                background: red;
                position:absolute;
                top:50px;
                left: -150px;
            }
            #div2{
                height: 50px;
                width: 20px;
                background: black;
                color: white;
                position:absolute;
                top:100px;
                right:-20px;
                line-height: 25px;
                cursor: pointer;
            }
        </style>
        <script>
            window.onload = function ()
            {
                odiv1 = document.getElementById(‘div1‘);
                odiv2 = document.getElementById(‘div2‘);
                var timer = null;

                odiv1.onmouseover= function ()
                {
                    ToMove(div1,0,10);
                }

                odiv1.onmouseout = function ()
                {
                    ToMove(div1,-150,-10);
                }


                function ToMove (obj,goal,speed)
                {
                    clearInterval(timer);
                    timer = setInterval(function(){
                        if(obj.offsetLeft == goal)
                        {
                            clearInterval(timer);
                        }
                        else
                        {
                            obj.style.left = obj.offsetLeft + speed + ‘px‘;
                        }
                    },30);
                }
            }
        </script>    
    </head>
    <body>
        
        <div id="div1"><div id="div2">分享</div></div>
        
    </body>    

</html>

 

js运动 分享到

标签:

原文地址:http://www.cnblogs.com/mayufo/p/4321811.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!