要增加resize事件,
在resize事件中调用这个MoveLayer方法

解决方案 »

  1.   

    图片跟着屏幕跑是scroll  和 resize(这个是屏幕放大和缩小)   并不是20毫秒读一次他的位置
    你的代码看不懂   ps:完整的例子都没贴出来
    <div id="ss" style=" left:10px; top:10px; width:300px; height:50px; background:#FFFF66; position:absolute"></div>
    hehe<br>hehe<br>hehe<br>hehe<br>hehe<br>hehe<br>hehe<br>hehe<br>hehe<br>hehe<br>hehe<br>hehe<br>hehe<br>hehe<br>hehe<br>hehe<br>hehe<br>hehe<br>hehe<br>hehe<br>hehe<br>hehe<br>hehe<br>hehe<br>hehe<br>hehe<br>hehe<br>hehe<br>hehe<br>hehe<br>hehe<br>hehe<br>hehe<br>hehe<br>hehe<br>hehe<script>
    window.onresize = gg;
    window.onscroll = gg;
    function gg(){
    document.getElementById("ss").style.top = 10 + parseInt(document.body.scrollTop,10) 
    document.getElementById("ss").style.left =10 + parseInt(document.body.scrollLeft,10) }
    </script>
    一个简单的例子!~
      

  2.   

    w3c浏览器使用fiexd属性,ie参考expression<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
      <head>
        <style>
            body
            {
             margin:0px;
             }
            #divFloat
            {
             width:100px;
             height:60px;
             border:solid 1px black;
             position:fixed !important;/*w3c*/
             position:absolute;/*ie*/
             right:0px;
             top:expression(this.offsetParent.scrollTop);
             }
        </style>
      </head>
      <body>
        <div id="divFloat"></div>
        <br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
        <br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
        <br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
        <br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
        <br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
        <br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
        <br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
        <br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
      </body>
    </html>
      

  3.   

    发现还是不行。
    在css+div制作的网页中位置无法改变。
    还望进一步指教。
      

  4.   

    对于支持position:fixed;定位的浏览器 如Chrome和FF 非常简单
    IE 7.0 不知道支不支持,IE 6.0是不支持的.可以通过先 position:absolute;设定绝对定位  把对像放在 BODY下面,不要放在其它容器下面.因为position: absolute;也是受上级容器影响
    然后用 .style.top;left right bottom 等来改变对像位置
    最好不要用resize事件来执行. resize会有延迟. 用setInterval //重复执行来定位
      

  5.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    按楼主的代码这么改下
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    </head>
    <body style="color:#eee">
    <script>
    function initAds(layerID) 

      document.getElementById(layerID).style.top= -200+'px';//设置onLoad事件激发以后,层相对于固定后的y方向位置  
      document.getElementById(layerID).style.visibility ='visible'//设置层为可见 
      setInterval(MoveLayer,  10);//设置25毫秒后再调用函数MoveLayers()
    } function MoveLayer() 
    {  
      var layerName = document.getElementById("AdLayer");
      var xs  = 100;
      var  ys = 100 + document.documentElement.scrollTop;//层固定于浏览器的y方向位置 
      var  ys = ys + (ys - layerName.offsetTop)*.40;
      layerName.style.top = ys + 'px';  
      layerName.style.left = xs + 'px'; ;//移动层    

    document.write(" <div id='AdLayer' style='color:#00f;position:absolute;z-index:20; width:100px; text-align:center;'> abcd</div>");
    initAds('AdLayer');
    </script>
    <br />***<br />***<br />***<br />***<br />***<br />***<br />***<br />***
    <br />***<br />***<br />***<br />***<br />***<br />***<br />***<br />***
    <br />***<br />***<br />***<br />***<br />***<br />***<br />***<br />***
    </body>
    </html>