div反弹
2016-07-04 12:22
344 查看
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>div反弹</title>
<script type="text/javascript">
var x=1;
var y=1;
function div()
{
var obj=document.getElementById("div1");
obj.style.top=parseInt(obj.style.top)+y+"px";
obj.style.left=parseInt(obj.style.left)+x+"px";
if(x==1&&y==1){
if(parseInt(obj.style.top)>=screen.height-parseInt(obj.style.height)-80)
{
x=1;
y=-1;
}
if(parseInt(obj.style.left)>=screen.width-parseInt(obj.style.width))
{
x=-1;
y=1;
}
}
if(x==1&&y==-1)
{
if(parseInt(obj.style.top)<=0)
{
x=1;y=1;
}
if(parseInt(obj.style.left)>=screen.width-parseInt(obj.style.width))
{
x=-1;
y=-1;
}
}
if(x==-1&&y==-1){
if(parseInt(obj.style.top)<=0)
{
x=-1;y=1;
}
if(parseInt(obj.style.left)<=0)
{
x=1;y=-1;
}
}
if(x==-1&&y==1)
{
if(parseInt(obj.style.left)<=0)
{
x=1;y=1;
}
if(parseInt(obj.style.top)>=screen.height-parseInt(obj.style.height)-80)
{
x=-1;
y=-1;
}
}
setTimeout("div()",1);
}
</script>
</head>
<body>
<div id="div1" style="position:absolute; height:100px;width:100px; background-color:#609; left:0;top:0;" onclick="div()" ></div>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>div反弹</title>
<script type="text/javascript">
var x=1;
var y=1;
function div()
{
var obj=document.getElementById("div1");
obj.style.top=parseInt(obj.style.top)+y+"px";
obj.style.left=parseInt(obj.style.left)+x+"px";
if(x==1&&y==1){
if(parseInt(obj.style.top)>=screen.height-parseInt(obj.style.height)-80)
{
x=1;
y=-1;
}
if(parseInt(obj.style.left)>=screen.width-parseInt(obj.style.width))
{
x=-1;
y=1;
}
}
if(x==1&&y==-1)
{
if(parseInt(obj.style.top)<=0)
{
x=1;y=1;
}
if(parseInt(obj.style.left)>=screen.width-parseInt(obj.style.width))
{
x=-1;
y=-1;
}
}
if(x==-1&&y==-1){
if(parseInt(obj.style.top)<=0)
{
x=-1;y=1;
}
if(parseInt(obj.style.left)<=0)
{
x=1;y=-1;
}
}
if(x==-1&&y==1)
{
if(parseInt(obj.style.left)<=0)
{
x=1;y=1;
}
if(parseInt(obj.style.top)>=screen.height-parseInt(obj.style.height)-80)
{
x=-1;
y=-1;
}
}
setTimeout("div()",1);
}
</script>
</head>
<body>
<div id="div1" style="position:absolute; height:100px;width:100px; background-color:#609; left:0;top:0;" onclick="div()" ></div>
</body>
</html>
相关文章推荐
- Java NIO 学习(一)--简介
- Java判断字符串是否为空方法总结
- hello world (android studio DNK )
- 为什么用copy for NSString属性?
- 数据复制评测:insert into 与 select into 对比
- TheDAO被攻击事件考察报告
- FZU 2124 吃豆人(BFS)
- VMware虚拟机中显示CPU不支持VT的解决方法
- 【腾讯bugly干货分享】HTML 5 视频直播一站式扫盲
- poj1328 Radar Installation 贪心
- 06、[]的使用
- Java提高篇之hashCode
- Oracle 动态SQL语句
- 三、观察者模式
- 测试博客
- poi-3.1-final 增加数据验证(between and操作符)
- CMake Error: Could not find CMAKE_ROOT !!!(ubuntu14.04)
- python小打小闹之简陋版BBS
- Android 开发(启动页)
- ❀❀ 名词解释(PM、PD、UE、UI、RD....)