var xpos=0;//x轴的坐标像素 var ypos=0;//y轴的坐标像素 var xon=0;//控制在x轴上的方向 var yon=0;//控制y轴上的方向 var step=0.3;//移动速度 function aa(){alert('aa');} function randomMove() { var width=document.documentElement.offsetWidth;//浏览器宽度 // alert(width); var height=document.documentElement.offsetHeight;//浏览器高度 //var width=document.documentElement.offsetWidth;//浏览器宽度 (这里用offsetWidth也行,但在dreamweaver中必须用documentElement,不能用body!因为dreamweaver所做//的是xhtml,而不是html) //var height=document.documentElement.offsetHeight;//浏览器高度 var layerWidth=document.getElementById("moveLayer").offsetWidth;//层宽度 var layerHeight=document.getElementById("moveLayer").offsetHeight;//层高度 document.getElementById("moveLayer").style.pixelTop=ypos+document.documentElement.scrollTop; //随滚动条移动(同时也刷新层移动后的位置)(如果div对象中没有style样式的话,将不会移动.因为找不到document.getElementById("moveLayer").style.这种style样式!) document.getElementById("moveLayer").style.pixelLeft=xpos+document.documentElement.scrollLeft;//随滚动条移动