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