javascript
<!DOCTYPE html PUBLTC "-//W3C//DTD XHML 1.0 Transitional//EN""http://www.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script language="javascript" >
<!--
//全局变量
directX=1;//X
directY=1;//Y
sunX=0;
sunY=0;
function sunMove(){
sunX+=directX;
sunY+=directY;
//修改div的left和top
var sundiv=document.getElementById("sundiv");
sundiv.style.top=sunY+"px";
sundiv.style.left=sunX+"px";
//X方向(offsetWidth)获得当前div的宽度
//window.alert(sundiv.style.top);
if(sunX+sundiv.offsetWidth>=document.body.clientWidth || sunX<=0 ){
directX=-directX;
window.alert(sundiv.style.left);
}
if(sunY+sundiv.offsetHeight>=document.body.clientHeight||sunY<=0 ){
directY=-directY;
}
}
setInterval("sunMove()",10);
//-->
</script>
</head>
<body style="background-image:url('year.jpg')">
<div id="sundiv" style="position:absolute">
<img src="1.gif"/>
</div>
</body>
</html>
代码运行有错 目标是使得图片在页面上飘动 碰到边界弹回 运行时左右可以上下不可以 top的值一直在0 1 徘徊 这是什么原因:?