<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<script>
window.onload=function(){
var x=document.getElementById("1st");
x.onmouseover=function(){
startmove(0)
}
x.onmouseout=function(){
startmove(-480)
}
}
var timmer=null;
function startmove(target){
clearInterval(timmer)
var x=document.getElementById("1st");
setInterval(function(){
var speed=0;
speed=(target-x.offsetLeft)/10
speed=speed>0?Math.ceil(speed):Math.floor(speed);
if(x.offsetLeft==target){
clearInterval(timmer)
}else{
x.style.left=x.offsetLeft+speed+"px";
}
},30)
}
</script>
</head>
<body>
<div id="1st" style="position: absolute; width: 500px; height: 100px; left: -480px; top: 262px;background:#00F"></div>
</body>
</html>
定时器那里, timmer = setInterval(