<HTML><HEAD><SCRIPT LANGUAGE="JavaScript">
window.onerror = null;
var topMargin = 100;
var slideTime = 10;
var ie4 = (document.all);
var ns4 = (document.layers);
function layerObject(id,left) {
if(ie4) {
this.obj = document.all[id].style;
this.obj.left = left;
return this.obj;
}
else if(ns4) {
this.obj = document.layers[id];
this.obj.left = left;
return this.obj;
  }
}
function layerSetup() {
floatLyr = new layerObject('floatLayer', pageWidth * .5);
window.setInterval("main()", 10)
}
function floatObject() {
if (ns4) {
findHt = window.innerHeight;
} else if(ie4) {
findHt = document.body.clientHeight;
  }

function main() {
if (ns4) {
this.currentY = document.layers["floatLayer"].top;
this.scrollTop = window.pageYOffset;
mainTrigger();
}
else if(ie4) {
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 )) {
if ( ie4 )document.all.floatLayer.style.pixelTop = newY;
if ( ns4 )document.layers["floatLayer"].top = newY;
  }
}
function start() {
if(ns4) {
pageWidth = innerWidth;
pageHeight = innerHeight;
layerSetup();
floatObject();
}
else if(ie4) {
pageWidth = document.body.clientWidth;
pageHeight = document.body.clientHeight;
layerSetup();
floatObject();
  }
}</script></HEAD>
<BODY onLoad="start()">
<p>xd<p>xd<p>xd<p>xd<p>xd<p>xd<p>xd<p>xd<p>xd<p>xd<p>xd<p>xd<p>xd<p>xd<p>xd<p>xd<p>xd<p>xd<p>xd<p>xd<p>xd<p>xd<p>xd<p>xd<p>xd<p>xd<p>xd<p>xd<p>xd<p>xd<p>xd<p>xd<p>xd<p>xd<p>xd<p>xd<p>xd<p>xd<p>xd<p>xd<p>xd<p>xd<p>xd<p>xd<p>xd
<DIV id="floatLayer" style="position: absolute; height:200px; width:200px; left:30px; top:1px;z-index: 100"><img src=http://lucky.myrice.com/back.jpg width=100 height=100></DIV></HTML>

解决方案 »

  1.   

    是不是随滚动条动而移动,总在网页的一个固定位置?下面你看看
    <SCRIPT LANGUAGE="JavaScript">
    <!-- Begin
    window.onerror = null;
    var topMargin = 71;
    var slideTime = 500;
    var ns6 = (!document.all && document.getElementById);
    var ie4 = (document.all);
    var ns4 = (document.layers);
    function layerObject(id,left) {
    if (ns6) {
    this.obj = document.getElementById(id).style;
    this.obj.left = left;
    return this.obj;
    }
    else if(ie4) {
    this.obj = document.all[id].style;
    this.obj.left = left-300;
    return this.obj;
    }
    else if(ns4) {
    this.obj = document.layers[id];
    this.obj.left = left;
    return this.obj;
       }
    }
    function layerSetup() {
    floatLyr = new layerObject('floatLayer', pageWidth * .5);
    window.setInterval("main()", 10)
    }
    function floatObject() {
    if (ns4 || ns6) {
    findHt = window.innerHeight;
    } else if(ie4) {
    findHt = document.body.clientHeight;
       }

    function main() {
    if (ns4) {
    this.currentY = document.layers["floatLayer"].top;
    this.scrollTop = window.pageYOffset;
    mainTrigger();
    }
    else if(ns6) {
    this.currentY = parseInt(document.getElementById('floatLayer').style.top);
    this.scrollTop = scrollY;
    mainTrigger();
    } else if(ie4) {
    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 )) {
    if ( ie4 )document.all.floatLayer.style.pixelTop = newY;
    if ( ns4 )document.layers["floatLayer"].top = newY;
    if ( ns6 )document.getElementById('floatLayer').style.top = newY + "px";
       }
    }
    function start() {
    if(ns6||ns4) {
    pageWidth = innerWidth;
    pageHeight = innerHeight;
    layerSetup();
    floatObject();
    }
    else if(ie4) {
    pageWidth = document.body.clientWidth;
    pageHeight = document.body.clientHeight;
    layerSetup();
    floatObject();
       }
    }
    //  End -->
    </script>________________________
    <body bgcolor="#FFFFFF" text="#000000" onLoad="start()">
    <DIV id="floatLayer" style="position: absolute; height:89px; width:91px; left:51px; top:22px;z-index: 100; background-color: #00CCFF; layer-background-color: #00CCFF; border: 1px none #000000"> 
      <!$MG_havereinder>
    </DIV>
    快慢可以自己调
      

  2.   

    哦,原来你说的是滚动条,那孟子和wukunrong(银恋仙儿)的方法都可以
      

  3.   


    原来两个是一样的啊,不好意思没看着
    其中
    var topMargin = 71;
    是离上面的高度
    this.obj.left = left-300;离左边的宽度
    如this.obj.left = left;是在中间,越往左减的数越大
    一般是ie4是判断ie浏览器中显示的
    别的一般就不用管了。
    var slideTime = 500;是快慢,越大平滑度越好,也越慢
      

  4.   

    孟子E章, wukunrong(银恋仙儿) 
    你们能不能告诉我我图层为什么始终会在多行文本框的后面呢?
    我现在要的效果是必须图层在最前面呀??
    多行文本框,我并没有放在图层里,为什么它会跑到图层的前面呢??
    在线等待,拜托!!