<!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>无标题文档</title>
</head>
<style>
div{
position:absolute;}
</style>
<body>
<div id="imgs" width="130px" height="120px">
<img src="aa.jpg" width="100px" height="100px"/>
</div>
</body>
<script>
var img=document.getElementById("imgs");
var yan=true;
var w=document.documentElement.clientWidth-130,h=document.documentElement.clientHeight-120;
function suiji(){
//控制产生的随机数不能小于0,并且不能大于指定的屏幕高与宽。
if(x<0 || x>w) {
if(y<0 || y>h){
yan=false;
}
}else{
var x=parseInt(Math.random()*500);
var y=parseInt(Math.random()*1000);
img.style.top=x+"px";
img.style.left=y+"px";
}
setTimeout("suiji()","1000");
}
suiji();
</script>
</html>