Newbie_小白
没有都对的别人,也没有全错的自己,至少要有自己的坚持,无关他人、无关外物!

代码:
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<style>
#div {
width: 200px;
height: 500px;
background: chartreuse;
position: absolute;
left: -200px;
top: 0px;
}

#div span {
width: 20px;
height: 70px;
background: fuchsia;
position: absolute;
right: -20px;
top: 100px;

}

</style>
<script>
window.onload = function () {
var oDiv = document.getElementById("div");
var iTarget = null;
oDiv.onmouseover = function () {
startMove( 0);

};
oDiv.onmouseout = function () {
startMove(-200);

}


var timer = null;

function startMove( iTarget) {

clearInterval(timer);
timer = setInterval(function () {
var speed=0;
if(oDiv.offsetLeft>iTarget){
speed=-10;
}else{
speed=10;
}
if (oDiv.offsetLeft == iTarget) {
clearInterval(timer);
} else {
oDiv.style.left = oDiv.offsetLeft + speed + "px";
}
},

30
)

}


}

</script>
</head>
<body>
<div id="div">
<span>分享到</span>
</div>


</body>
</html>

 

运行结果:

初始:

鼠标移入:

鼠标移出:

 

posted on 2016-03-11 08:37  Newbie_小白  阅读(300)  评论(0编辑  收藏  举报