首页 > 代码库 > js笔记----(运动)分享 隐藏/显示

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

<!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笔记----(运动)分享 隐藏/显示