<style>
*{margin:0;padding:0;}
#div1{width:150px;height:200px;position:absolute;top:0px;left:-150px;background:yellow;}
#div1 span{width:20px;heigth:70px;background:green;right:-20px;top:70px;display:block;position:absolute;}
</style>
<div id="div1"><span id="span1">分享到</span></div>
<script>
window.onload=function(){
var oDiv1 = document.getElementById(‘div1‘);
var oSpan = document.getElementById(‘span1‘);
oDiv1.onmouseover=function(){
startMove(10,0);
}
oDiv1.onmouseout=function(){
startMove(-10,-150);
}
}
//定义方法
var timer = null;
function startMove(speed,iTarget){
var oDiv1 = document.getElementById(‘div1‘);
var oSpan = document.getElementById(‘span‘);
clearInterval(timer);
timer = setInterval(function(){
if(oDiv1.offsetLeft==iTarget){
clearInterval(timer);
}else{
oDiv1.style.left = oDiv1.offsetLeft+speed+‘px‘;
}
},30)
}
</script>
原文地址:http://www.cnblogs.com/jewave/p/3838051.html