日期:2014-05-16 浏览次数:20423 次
<script type="text/javascript"> var directX=1; var directY=1; var sunX=0; var sunY=0; function move(){ sunX+=directX; sunY+=directY; var sunDiv=$("sun"); sunDiv.style.left=sunX+"px"; sunDiv.style.top=sunY+"px"; //判断小球的x坐标 //offsetWitdth用于获取当前对象的宽度 if(sunX+sunDiv.offsetWidth>=document.body.clientWidth || sunX<=0){ directX=-directX; } if(sunY+sunDiv.offsetHeight>=document.body.clientHeight || sunY<=0){ directY=-directY; } } window.setInterval("move()",50); function $(id){ return document.getElementById(id); } </script>