太晚了,哈哈。今天有点神经,继续发表吧。
<!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>
<style>
div{
position:absolute;
}
</style>
</head>
<body>
<div id="divImg">
<img src="http://a0.att.hudong.com/68/12/01300000012894119556127736723.jpg" width="130" height="180">
</div>
<script language="javascript" type="text/javascript">
//获取图片div对象
var img1=document.getElementById("divImg");
//设置div起始点的坐标(0,0)左上角坐标
var x=0,y=0;
//右下边求出图片起始点最大X和Y的坐标值
var w=window.screen.availWidth-130,h=window.screen.availHeight-180;
function floatimg(){
//随机产生坐标x和坐标Y的值(都是从零到起始点最大X和Y的坐标值)
x=Math.round(Math.random()*(w));
y=Math.round(Math.random()*(h));
//alert(x+","+y);
img1.style.left=x+"px";
img1.style.top=y+"px";
setTimeout("floatimg()",1000);
}
floatimg();
</script>
</body>
</html>