<html>
<head>
</head>
<script language="javascript" type="text/javascript">
<!--
var directX=1;
var directY=1;
var sunX=0;
var sunY=0;
var speed=12;
var tempdiv; function createLine(){
tempdiv=document.createElement("img");
tempdiv.style.width="400px";
tempdiv.style.height="10px";
tempdiv.style.position="absolute";
tempdiv.style.top="350px";
tempdiv.style.left="300px";
tempdiv.border='1px';
tempdiv.id="linediv";
tempdiv.style.backgroundColor="blue";
document.body.appendChild(tempdiv);
} function move(){
sunX+=directX*speed;
sunY+=directY*speed; var top=parseFloat(linediv.style.top);
var left=parseFloat(linediv.style.left);
var width=parseFloat(linediv.style.width);
var height=parseFloat(linediv.style.height); ballimg.style.left=sunX+"px";
ballimg.style.top=sunY+"px";
if(sunX+ballimg.offsetWidth>document.body.clientWidth||sunX<0){
directX=-directX;
}
<!-- 迫于无奈的处理办法(sunY<top+height+50)。 不然球在div下方会不停的弹--> if((sunY<top+height+50)&&(sunY+ballimg.offsetHeight>top&&sunX>left&&sunX<width+left-29)||sunY<0){
directY=-directY;
}
}
function keyBoard(){
if(event.keyCode==37){
document.getElementById("ballimg").nextSibling.style.left-=speed; }else if(event.keyCode==39){
document.getElementById("ballimg").nextSibling.style.left+=speed;
}

}
setInterval("move()",10);
//-->
</script><body onkeydown="return keyBoard()" onload="createLine()">
<IMG style="position:absolute; top:0px;left:0px;"  id="ballimg" SRC="小球.gif" BORDER="0" ALT="">
</body>
</html>
问题1:
我想通过按下键盘 来改变div的left值,但改不了是哪错了?
1.1 试过直接用id取left,
1.2 试过用相邻节点的办法取div。
但是都不行。问题2
怎么判断小球撞到挡板时候的条件..我在42行用的很笨的办法(sunY<top+height+50).求指教。。分不多,别嫌弃