<!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>
<script language="javascript">
var Atop=0;
function inix(){
    Atop=document.getElementByID("Layer1").style.pixelTop;
}
function move(){
    document.getElementByID("Layer1").style.pixelTop=Atop+document.body.scrolltop;
}
window.onscroll=move;
</script>
<style type="text/css">
<!--
#Layer1 {
position:absolute;
left:48px;
top:49px;
width:82px;
height:82px;
z-index:1;
}
-->
</style>
</head><body onload="inix()">
<div id="Layer1"><img src="images/float_advclose1.gif" width="80" height="80" /></div>
<table width="200" border="1" align="center">
  <tr>
    <td><img src="images/xiaojie1.jpg" width="768" height="1113" /></td>
  </tr>
</table>
</body>
</html>
一直不浮动  找不出原因   大家帮忙指点下

解决方案 »

  1.   

    我有两个浮动iframe的js组件,有需要发给你.我msn:[email protected]
      

  2.   

    能不能转换下思想,用setTimeout实现定时订位
      

  3.   

    把<!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"
       去掉
      

  4.   

    LZ的代码有几处错误:
    1 Atop=document.getElementByID("Layer1").style.pixelTop; 
    应该写为
      Atop=document.getElementById("Layer1").style.pixelTop; 2 document.getElementByID("Layer1").style.pixelTop=Atop+document.body.scrolltop;
    应该写为
      document.getElementByID("Layer1").style.pixelTop=Atop+document.body.scrollTop;*大小写要注意哦关于窗口不能浮动的问题,我不大懂。
    我试了用LZ的方法,window.onscroll=move,似乎没执行。
    继续关注....
      

  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>
            <script language="javascript">
                var Atop = 0;
                function inix(){
                    Atop = document.getElementById("Layer1").style.pixelTop;
                }
                
                function move(){
                    document.getElementById("Layer1").style.pixelTop = Atop + document.documentElement.scrollTop;
                }
                
                window.onscroll = move;
            </script>
            <style type="text/css">
            <!-- #Layer1 {
                position: absolute;
                left: 48px;
                top: 49px;
                width: 82px;
                height: 82px;
                z-index: 1;
            }
            -->
            </style>
        </head>
        <body onload="inix();">
            <div id="Layer1">
                <img src="images/float_advclose1.gif" width="80" height="80" />
            </div>
            <table width="200" border="1" align="center">
                <tr>
                    <td>
                        <img src="images/xiaojie1.jpg" width="768" height="1113" />
                    </td>
                </tr>
            </table>
        </body>
    </html>
      

  6.   

    改进版
    <!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>
            <script language="javascript">
                var Atop = 0;
                function inix(){
                
                    Atop = findPos(document.getElementById("Layer1"))[1];
                }
                
                function move(){
                    document.getElementById("Layer1").style.pixelTop = Atop + document.documentElement.scrollTop;
                }
                
                function findPos(obj){
                    var curleft = curtop = 0;
                    if (obj.offsetParent) {
                        do {
                            curleft += obj.offsetLeft;
                            curtop += obj.offsetTop;
                        }
                        while (obj = obj.offsetParent);
                    }
                    return [curleft, curtop];
                }
                
                window.onscroll = move;
            </script>
            <style type="text/css">
            <!-- #Layer1 {
                position: absolute;
                left: 48px;
                top: 49px;
                width: 82px;
                height: 82px;
                z-index: 1;
            }
            -->
            </style>
        </head>
        <body onload="inix();">
            <div id="Layer1">
                <img src="images/float_advclose1.gif" width="80" height="80" />
            </div>
            <table width="200" border="1" align="center">
                <tr>
                    <td>
                        <img src="images/xiaojie1.jpg" width="768" height="1113" />
                    </td>
                </tr>
            </table>
        </body>
    </html>
      

  7.   

    窗体不移动的问题
    我改了一处的代码。
    将原先的代码
        document.getElementByID("Layer1").style.pixelTop=Atop+document.body.scrolltop; 
    改为
         document.getElementById("Layer1").style.pixelTop=Atop+document.documentElement.scrollTop; 还有一个问题,就是
    Atop的值为何总是0...
      

  8.   

    css属性你没有设置过,获取的时候就是空,要获得一个元素在页面上的绝对位置要先获得这个元素与父元素的相对位置再获得父元素的父元素的相对位置, 一直循环,到根元素就可以了,然后把相对位置相加,top和left的取法是一样的           function findPos(obj){
                    var curleft = curtop = 0;
                    if (obj.offsetParent) {
                        do {
                            curleft += obj.offsetLeft;
                            curtop += obj.offsetTop;
                        }
                        while (obj = obj.offsetParent);
                    }
                    return [curleft, curtop];
                }
      

  9.   

      我是 3楼的那个 四楼的问题我还没看到 把大小写写正确 然后就是我上面的东西去掉就可以了 那是默认的 没用有了就不会动
    我自己出现过这种错误..还有几是 不稳定一样 虽然滚动了 但是 又跳到上面去了 就是top=0  了郁闷 但是同样的代码别人copy了运行又可以 .......是运气吗..
      

  10.   

    用一下这个<div id='ad' style='position:absolute;z-index:10;'><a href='/AdvertisementInfo/AdvertisementCount.aspx?id=22' target='_blank'><img src='/uploadfiles/adv/dcf1b82d-84ed-41e8-9174-f19f8f462cba_fudong.jpg' border='0' width=100 height=100></a><br><a href='#' onclick='javascript:CloseAD4()'><b>关闭</b></a></div> 
    <script>  
    var x = 50,y = 60  
    var xin = true, yin = true  
    var step = 1  
    var delay = 50  
    var obj=document.getElementById('ad')  
    function floatAD() { 
    var L=T=0   
    var R= document.body.clientWidth-obj.offsetWidth  
    var B = document.body.clientHeight-obj.offsetHeight   
    obj.style.left = x + document.body.scrollLeft  
    obj.style.top = y + document.body.scrollTop  
    x = x + step*(xin?1:-1)  
    if (x < L) { xin = true; x = L}  
    if (x > R){ xin = false; x = R}   
    y = y + step*(yin?1:-1)  
    if (y < T) { yin = true; y = T }  
    if (y > B) { yin = false; y = B }  

    var itl= setInterval('floatAD()', delay)  
    obj.onmouseover=function(){clearInterval(itl)}  
    obj.onmouseout=function(){itl=setInterval('floatAD()', delay)}  
    </script><script language=javascript>
    function CloseAD4()
    {
    document.getElementById('ad').style.visibility = "hidden";
    }
    </script>
      

  11.   

     郁闷讲的那么复杂   把 <!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" 
      去掉  再把你的大小写写好  像四楼说的那几个  还有就是 把样式写在层里面就好了 

    position:absolute; 
    left:48px; 
    top:49px; 
    width:82px; 
    height:82px; 
    z-index:1; 剪掉 放到行内
    结果就是
    <div id="Layer1" 
    style="position:absolute; 
    left:48px; 
    top:49px; 
    width:82px; 
    height:82px; 
    z-index:1"> <img src="images/float_advclose1.gif" width="80" height="80" /> </div>