求助滑塊運動問題?。。?!
下面這段代碼到底哪里錯了,為什么它不會停止,而是一直滑動,求解
window.onload=function(){
var check=document.getElementById("check");
? check.onmouseover=function(){
? startMove(1,0);}
? check.onmouseout=function(){
? startMove(1,-100);}
? }
? var time=null;
? function startMove(speed,target){
? ? var box=document.getElementById("box");
clearInterval(time);
time=setInterval(function(){
if(box.offsetLeft==target)
clearInterval(time);
else
box.style.left=box.offsetLeft+speed+"px";
},30);
? }?
??
2016-06-05
if else 語句錯了,else后面沒加花括號.
2016-06-04
抱歉,第二個請忽略,回復(fù)錯了
2016-06-04
2016-06-04
window.onload=function(){
var check=document.getElementById("check");
? check.onmouseover=function(){
? startMove(1,0);}
? check.onmouseout=function(){
? startMove(1,-100);}
? }
? var time=null;
? function startMove(speed,target){
? ? var box=document.getElementById("box");
clearInterval(time);
time=setInterval(function(){
if(box.offsetLeft==target){
clearInterval(time);}
else{
box.style.left=box.offsetLeft+speed+"px";}
},30);
? }?