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

时间:2021-02-01 17:08:03
<!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();
}
oDiv.onmouseout = function () {
StarMove(-);
}
}
var timer = null;
function StarMove(Targer)
{
var iSpeed = ;
var oDiv = document.getElementById('box');
clearInterval(timer);
if (oDiv.offsetLeft < Targer) {
iSpeed = ;
} else {
iSpeed = -;
} timer = setInterval(function () {
if (oDiv.offsetLeft == Targer) {
clearInterval(timer);
}
else {
oDiv.style.left = oDiv.offsetLeft + iSpeed + 'px';
} }, );
}
</script>
</head>
<body>
<div id="box">
<span>分享</span>
</div>
</body>
</html>