[問題] JS 改用marginLeft後的速度變化
這兩天開始初碰javascript,
寫了一個小DIV在大DIV中跑的程式,
原本依照老師的用法有設相對跟絕對位置,(←有很順利的跑)
後來改用marginLeft跟marginTop後,
居然出現了奇妙的速度變化....
想問下板上各位先進這是為什麼.....囧
--以下附上程式碼--
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"" rel="nofollow">http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="" rel="nofollow">http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>DIV</title>
<style type="text/css">
#aa {
border:1px solid #000000;
width:1000px;
height:700px;
}
#bb{
border:1px solid #000000;
width:100px;
height:100px;
}
</style>
</head>
<body>
<div id="aa">
<div id="bb"></div>
</div>
<script type="text/javascript">
function run(){
var obj = document.getElementById("bb");
if(obj.offsetLeft<=900 && obj.offsetTop<=0){
obj.style.marginLeft=(obj.offsetLeft+10)+"px";
}else if(obj.offsetTop<=600 && obj.offsetLeft>=900){
obj.style.marginTop=(obj.offsetTop+10)+"px";
}
else if(obj.offsetLeft>0){
obj.style.marginLeft=(obj.offsetLeft-10)+"px";
}else{
obj.style.marginTop=(obj.offsetTop-10)+"px";
}
}
setInterval(run,50);
</script>
</body>
</html>
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.118.17.64
※ 文章網址: http://www.ptt.cc/bbs/Ajax/M.1401949161.A.990.html
→
06/05 16:55, , 1F
06/05 16:55, 1F
→
06/05 17:05, , 2F
06/05 17:05, 2F
→
06/05 17:08, , 3F
06/05 17:08, 3F
→
06/05 17:08, , 4F
06/05 17:08, 4F
→
06/05 17:11, , 5F
06/05 17:11, 5F
→
06/05 17:50, , 6F
06/05 17:50, 6F
→
06/05 18:12, , 7F
06/05 18:12, 7F
→
06/05 23:03, , 8F
06/05 23:03, 8F
→
06/05 23:04, , 9F
06/05 23:04, 9F
→
06/05 23:20, , 10F
06/05 23:20, 10F
→
06/05 23:23, , 11F
06/05 23:23, 11F
→
06/05 23:24, , 12F
06/05 23:24, 12F
→
06/05 23:25, , 13F
06/05 23:25, 13F
→
06/05 23:25, , 14F
06/05 23:25, 14F
→
06/05 23:39, , 15F
06/05 23:39, 15F
→
06/06 00:19, , 16F
06/06 00:19, 16F
Ajax 近期熱門文章
PTT數位生活區 即時熱門文章