求助滑塊運(yùn)動(dòng)問(wèn)題?。。?!
下面這段代碼到底哪里錯(cuò)了,為什么它不會(huì)停止,而是一直滑動(dòng),求解
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 語(yǔ)句錯(cuò)了,else后面沒(méi)加花括號(hào).
2016-06-04
抱歉,第二個(gè)請(qǐng)忽略,回復(fù)錯(cuò)了
2016-06-04
<!DOCTYPE?html> <html> <head> <meta?charset="UTF-8"> <title></title> <style> *{ margin:?0; padding:?0; } a{ text-decoration:?none; } div?{ width:475px; background:#eeeeee; margin:auto; text-align:?center; } #main?{ display:?block; margin:auto; } #main?li?{ display:?inline; } li:nth-child(2){ position:?relative; } #child?{ position:?absolute; top:?100%; left:?0; display:?none; } li:nth-child(2):hover?#child{ display:?block; background:#eeeeee;? } </style> </head> <div> <ul?id="main"> <li?> <a?href="#">首頁(yè)</a> </li> <li> <a?href="#">課程大廳</a> <ul?id="child"> <li><a?href="#">javaScript</a></li> <li><a?href="#">JQuery</a></li> </ul> </li> <li><a?href="#">學(xué)習(xí)中心</a></li> <li><a?href="#">經(jīng)典案例</a></li> <li><a?href="#">關(guān)于我們</a></li> </ul> </div> </body> </html>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);
? }?