| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 489 人关注过本帖
标题:javascript
只看楼主 加入收藏
hqwan890622
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2012-8-2
结帖率:0
收藏
已结贴  问题点数:2 回复次数:1 
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
Sunpeng_Bccn
Rank: 2
等 级:论坛游民
威 望:2
帖 子:19
专家分:34
注 册:2012-8-4
收藏
得分:2 
你看是不是少了一个重新附初值,window.alert(sundiv.style.bottom);
2012-08-04 20:54
快速回复:javascript
数据加载中...
 
   



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

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