js代码:
<script type="text/javascript">
window.onload=function(){
//获取当前div
var odiv=document.getElementById("div");
//获取当前浏览器尺寸
var screen_w=document.body.clientWidth-200;
var screen_h=document.body.clientHeight-260;
//alert(x)
function float(){
var x=Math.random()*screen_w;
var y=Math.random()*screen_h;
odiv.style.top=y+"px";
odiv.style.left=x+"px";
}
setInterval(float,1000);
}
</script>
css代码:
html,body{
width: 100%;
height: 100%;
}
#div{
width: 200px;
height: 260px;
background: #ccc;
position: absolute;
top: 0px;
left: 0px;
transition: all 1s linear;
}
html代码:
<div id="div"></div>