<html>
<head>
<title>Document</title> </head>
<body style="background-image:URL('./b1.png')">
<div id="sundiv" style="position:absolute">
<img src="太阳.png"/>
</div>
<script language="javascript" type="text/javascript"> //定义全局变量
directX=1;//x轴的方向
directY=1;//y轴的方向
//上面两个全局变量似乎没有生效
sunX=0;//小太阳的坐标x
sunY=0;//小太阳的坐标y
function sunMove(){ sunX+=directX;
sunY+=directY;
//这条语句无法执行,竟然是因为<!doctype html>存在 //修改div的left top
sundiv.style.top=sunY+"px";
//window.alert(sunY);
//window.alert(sundiv.style.top);
sundiv.style.left=sunX+"px";
//判断什么时候,转变方法
//x方法(offsetWidth可以返回当前这个对象的实际宽度)
if(sunX+sundiv.offsetWidth>=document.body.clientWidth||sunX<=0){
//window.alert(directX);
//directX-=directX;
directX=-directX;
}
//判断y
if(sunY+sundiv.offsetHeight>=document.body.clientHeight||sunY<=0){
//directY-=directY;
directY=-directY;
//window.alert(directY);
}
} setInterval("sunMove()",3);
//这里写的是setInterval("sunMove()",100);,而不是
//setInterval("sunMove",100);
</script>
</body>
</html>
<!-- 运行上述代码时,出现一个巨坑,浏览器没有更新代码,害我刷新对运行结果根本影响。还有<!DOCTYPE html>这句话使代码无法正确运行 -->

最新文章

  1. C 标准库系列之ctype.h
  2. ubuntu locale 语言设置
  3. eclipse使用时jar不在libraries
  4. 【读书笔记《Android游戏编程之从零开始》】2.Hello,World!
  5. ACCESS数据库C#操作类(包含事务)
  6. 20160728noip模拟赛zld
  7. hibernateTemplate HibernateDaoSupport不建议在Spring与Hibernate整合中使用
  8. A Brief Introduction to the Design of UBIFS
  9. 机器学习之SVM(支持向量机)
  10. php中文编码
  11. POJ1700:Crossing River(过河问题)
  12. [Redux] Passing the Store Down Implicitly via Context
  13. C#文本文件读写
  14. CF卡技术详解——笔记
  15. RPC和RMI的区别(Difference Between RPC and RMI)
  16. Phaser小游戏
  17. LODOP之票据连续套打笔记&lt;一&gt;
  18. python 字典详解
  19. HTTP1.0、HTTP1.1 和 HTTP2.0 的区别
  20. sql百万级查询优化(转)

热门文章

  1. [C++设计模式] state 状态模式
  2. C++中一些个函数的使用
  3. 解决:cannot execute binary file
  4. bzoj4010【HNOI2015】菜肴制作
  5. POJ 2985 Treap平衡树(求第k大的元素)
  6. Linux系统运维之路
  7. OS开发之旅之App的生命周期【转载】
  8. 开源项目WebImageView载入图片
  9. java文本输入输出小结
  10. 转载 OSX开发推荐书籍列表