<!DOCTYPE html>
<html>
<head>
<title>动画</title>
<meta charset="utf-8">
<style type="text/css">
#div{
width: 200px;
height: 200px;
background: red;
position: relative;
left: -200px;
top: 0;
}
#div span{
width: 20px;
height: 50px;
background: blue;
position: absolute;
left: 200px;
top: 75px;
}
</style>
<script type="text/javascript">
window.onload=function()
{
var oDiv=document.getElementById('div');
oDiv.onmouseover=function()
{
startmove();
}
}
var timer =null;
function startmove()
{
clearInterval(timer);
var oDiv=document.getElementById('div');
var speed=10;
timer=setInterval(function(){
if (oDiv.offsetLeft == 0)
{
clearInterval(timer);
}else{
oDiv.style.left=oDiv.offsetLeft+speed+'px';
}
},30)
}
</script>
</head>
<body>
<div id="div" ><span id="share">分享</span></div>
</body>
</html>