通过JS的setTimeout事件来控制一个小方块绕屏幕移动:
<html>
<style type="text/css">
</style>
<script>
function autoMoveBox()
{
//debugger;
var windowHeight = window.innerHeight;
var windowWidth = window.innerWidth;
var box = document.getElementById("square");
var boxWidth = parseInt(box.style.width);
var boxHeight = parseInt(box.style.height);
var boxTop = parseInt(box.style.top);
var boxLeft = parseInt(box.style.left);
var size = 10;
// 左上角,开始右移
if( (boxTop-boxHeight<=0) && (boxLeft+boxWidth)<windowWidth )
{
box.style.left = boxLeft + size + "px";
}
else if((boxTop+boxHeight<windowHeight) && (boxLeft+boxWidth)>=windowWidth)
{
// 右上角,开始下移
box.style.top = boxTop + size + "px";
}
else if((boxTop+boxHeight)>=