<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="imgs">
<img src="1.jpg" width="100px" height="100px"/>
</div>
</body>
<script language="javascript" type="text/javascript">
var img=document.getElementById("imgs");
var yan=true;
var w=document.documentElement.clientWidth-130;
var h=document.documentElement.clientHeight-120;
function tiao(){
//控制产生的随机数不能小于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("tiao()","1000");
}
tiao();
</script>
</html>
406



被折叠的 条评论
为什么被折叠?



