為什么我的根本停不下來
window.onload=function(){
var odiv=document.getElementById("div1");
odiv.onmouseover=function(){
huaguo();
}
}
var timer=null;
function huaguo(){
var odiv=document.getElementById("div1");
timer=setInterval(function(){
if(odiv.offsetLeft==0) {
clearInterval(timer);
}
else{
? ? ? ? ? odiv.style.left=odiv.offsetLeft+10+"px";
? }
},30)
? ?
}
2015-08-04
offsetLeft包含邊框,clientLeft不包含邊框,,個人理解
2015-07-20
解決了,原來我沒設置css樣式里的margin,padding和border等于0,導致 if 判斷 錯誤
2015-07-20
你在定義函數之后需要再清一下你設置的timer,還缺少if條件判斷。你再仔細看看代碼。