*{margin:0;padding:0;} 为什么不写这个,就停不下来了?
<!DOCTYPE html>
<html>
<head>
<title>动画</title>
<style type="text/css">
#box{
width: 200px;
height: 100px;
background-color: black;
position: relative;
left:-200px;
}
#share{
width: 30px;
height: 50px;
background-color: blue;
position: absolute;
left:200px;
}
</style>
</head>
<body>
<div id="box"><span id="share"></span></div>
<script type="text/javascript">
window.onload=function(){
var odiv=document.getElementById('box');
odiv.onmouseover=function(){
startMove();
}
var timer=null;
function startMove(){
timer=setInterval(function(){
if(odiv.offsetLeft==0){
clearInterval(timer);
}
else{
odiv.style.left=odiv.offsetLeft+10+'px';
}
},30)
}
}
</script>
</body>
</html>