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

js笔记----(运动)分享 隐藏/显示

时间:2014-10-28 13:27:37      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   color   os   ar   java   sp   

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <style>
        body, div { padding:0px; margin:0px; }
        #box{ height:300px; width:200px; background-color:#ccc; position:absolute;left:-200px; margin-top:200px;border:1px solid #ffd800; border-radius:6px;}
        #box span{ height:85px; width:40px; position:absolute;left:200px; top:103px; line-height:40px; font-size:20px; background-color:yellow; font-weight:bold; text-align:center; border-radius:6px; border:1px solid #ffd800;}
    </style>
    <script type="text/javascript">
        window.onload = function () {
            var oDiv = document.getElementById(box);
            oDiv.onmouseover = function () {
                StarMove(0);
            }
            oDiv.onmouseout = function () {
                StarMove(-200);
            }
        }
        var timer = null;
        function StarMove(Targer)
        {
            var iSpeed = 0;
            var oDiv = document.getElementById(box);
            clearInterval(timer);
            if (oDiv.offsetLeft < Targer) {
                iSpeed = 10;
            } else {
                iSpeed = -10;
            }

            timer = setInterval(function () {
                if (oDiv.offsetLeft == Targer) {
                    clearInterval(timer);
                }
                else {
                        oDiv.style.left = oDiv.offsetLeft + iSpeed + px;
                }
                
            }, 30);
        }
    </script>
</head>
<body>
    <div id="box">
        <span>分享</span>
    </div>
</body>
</html>

 

js笔记----(运动)分享 隐藏/显示

标签:style   blog   http   io   color   os   ar   java   sp   

原文地址:http://www.cnblogs.com/juexin/p/4056420.html

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