您的位置:首页 > 其它

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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: