為什么鼠標移動到方塊上不會移動
<!doctype html>
<html>
? <head>
? ? <meta charset="UTF-8">
? ? <title>緩沖動畫</title>
<style type="text/css">
div body{
?margingin:0;
?padding:0;
}
?#div1{
? ?width:250px;
height:200px;
background:red;
position:relative;top:0px;left:-200px;
?}
</style>
<script>
?window.onload=function{
? ?oDiv = document.getElementById("div1");
oDiv.onmouseover = function(){
?startMove(0);
}
oDiv.onmouseout = function(){
?startMoove(-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);
?}
</script>
? </head>
? <body>
? ? <div id="div1"></div>
? </body>
</html>
2016-06-01
都不知道怎么回答好,你代碼寫錯了,window.onload=function(){}
timer = setInterval(function(){});