<HEAD><SCRIPT LANGUAGE="JavaScript">window.onerror = null;
var topMargin = 10; //离页面顶的距离
var slideTime = 1200; //滚动速度function layerObject(id,left) {
this.obj = document.all[id].style;
this.obj.left = left;
return this.obj;
}
function layerSetup() {
floatLyr = new layerObject('floatLayer', pageWidth * .5);
window.setInterval("main()", 10)
findHt = document.body.clientHeight;

function floatObject() {
findHt = document.body.clientHeight;

function main() {
this.currentY = floatLayer.style.pixelTop;
this.scrollTop = document.body.scrollTop;
mainTrigger();
   }function mainTrigger() {
var newTargetY = this.scrollTop + this.topMargin;
if ( this.currentY != newTargetY ) {
if ( newTargetY != this.targetY ) {
this.targetY = newTargetY;
floatStart();
}
animator();
   }
}
function floatStart() {
var now = new Date();
this.A = this.targetY - this.currentY;
this.B = Math.PI / ( 2 * this.slideTime );
this.C = now.getTime();
if (Math.abs(this.A) > this.findHt) {
this.D = this.A > 0 ? this.targetY - this.findHt : this.targetY + this.findHt;
this.A = this.A > 0 ? this.findHt : -this.findHt;
}
else {
this.D = this.currentY;
   }
}
function animator() {
var now = new Date();
var newY = this.A * Math.sin( this.B * ( now.getTime() - this.C ) ) + this.D;
newY = Math.round(newY);
if (( this.A > 0 && newY > this.currentY ) || ( this.A < 0 && newY < this.currentY )) {
document.all.floatLayer.style.pixelTop = newY;
   }
}
function start() {
pageWidth = document.body.clientWidth;
pageHeight = document.body.clientHeight;
layerSetup();
floatObject();
   }
</script></HEAD>
<BODY onLoad="start()">
<p>测试文字<p>测试文字<p>测试文字<p>测试文字<p>测试文字<p>测试文字<p>测试文字<p>测试文字<p>测试文字<p>测试文字<p>测试文字<p>测试文字<p>测试文字<p>测试文字<p>测试文字<p>测试文字
<DIV id="floatLayer" align=center style="position: absolute;background-color:#0099ff; height:200px; width:200px; left:30px; top:1px;z-index: 100">这是一个层相对窗口固定的例子啊!<br><img src=http://go.163.com/colorweb/javabk1.jpg hspace=20></DIV>