<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>我是广告</title>
<meta name="description" content="">
<meta name="keywords" content="">
<link href="" rel="stylesheet">
</head>
<body>
<div id="one" style="background:green;position:absolute;left:0;top:0;width:100px;height:100px;">我是广告我怕谁</div>
</body>
<script>
var x=0;
var y=0;
var xs=10;
var ys=10;
var one=document.getElementById("one");
function move()
{
x+=xs;
y+=ys;
if(x >= document.body.clientWidth-one.offsetWidth-20|| x <=0 ){
xs=-1*xs;
}
//这里注意document.body.clientHeight是html 跟 document.documentElement.clientHeight是xml html5 的区别
if(y >= document.documentElement.clientHeight-one.offsetHeight-20 || y <=0)
{
ys=-1*ys;
}
one.style.left=x+"px";
one.style.top=y+"px";
}
var dt=setInterval("move()",100);
one.onmouseover=function()
{
clearInterval(dt);
}
one.onmouseout=function()
{
dt=setInterval("move()", 100);
}
</script>
</html>