该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
*{
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;
}
window.οnlοad=function(){
var oDiv=document.getElementById("div1");
oDiv.οnmοuseοver=function(){
startMove(0);
}
oDiv.οnmοuseοut=function(){
startMove(-200);
}
}
var timer=null;
function startMove(iTarget){
clearInterval(timer);
var oDiv=document.getElementById("div1");
timer=setInterval(function(){
var speed=0;
if(oDiv.offsetLeft>iTarget){
speed=-10;
}
else
{
speed=10;
}
if(oDiv.offsetLeft==iTarget){
clearInterval(timer);
}else{
oDiv.style.left=oDiv.offsetLeft+speed+"px";
}
},30);
}