标题:javascript
取消只看楼主
hqwan890622
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2012-8-2
结帖率:0
已结贴  问题点数:2 回复次数:0 
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 徘徊 这是什么原因:?
搜索更多相关主题的帖子: html javascript function content 
2012-08-02 13:45



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-374598-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.023893 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved