我现在有一个div。
想无论页面最大化,或者缩小 ,
都让这个div 可以显示。。像对联一样。
并且是 显示在可见区的最底部.
尤其是滚动的时候也是。。

解决方案 »

  1.   


    var top;
            var left;
            function peixun() {
                var div = document.getElementById('div2009_2010');
                var docuTop = document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop;
                if (docuTop < document.body.clientHeight) {
                    div.style.posTop = docuTop + window.screen.availHeight - 330;
                }
            }
            function pp() {            /*var h1 = window.screen.availHeight - 165;
                if (document.body.clientHeight < h1)
                document.all.t1.style.top = window.screen.availHeight - 165;
                document.write("当前窗口宽:" + document.body.offsetWidth + "; 高:" + document.body.clientHeight + "aaaa" + (window.screen.availHeight));
                */
                var div = document.getElementById('div2009_2010');
                var docuTop = document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop;
                div.style.posTop = document.body.clientHeight - 165;
                div.style.posRight = 0;        }
            pp();
            window.onscroll = peixun;
            window.onresize = pp;我的代码。。
      

  2.   

    <body>
    <div style="position: absolute; bottom: 0;left: 0;">飘吧,左边!</div>
    <div style="position: absolute; bottom: 0;right: 0;">飘吧,右边!</div>
    </body>
    不管是最大化,还是缩小窗口。div都在页面底部。
      

  3.   


     <script type="text/javascript">
            window.onscroll = function() {
                var scrollTop = parseInt(document.body.scrollTop);
                var clientHeight = parseInt(document.body.clientHeight);
                var div = document.getElementById("div2009_2010");
                if (scrollTop <= clientHeight) {
                    div.style.top = scrollTop + clientHeight - 165 + "px";
                }
            }
            window.onresize = window.onscroll;
            function init() {
                var df = document.createDocumentFragment();
                for (var i = 0; i < 20; i++) {
                    var p = document.createElement("p");
                    p.appendChild(document.createTextNode(" Line " + i));
                    df.appendChild(p);
                }
                document.body.appendChild(df);
                window.onscroll();
            }
            function show() {
                document.getElementById("message").innerText = document.body.scrollHeight + ":::" + document.body.scrollTop;
                // parseInt(document.body.scrollTop) + parseInt(document.body.clientHeight) - 165 + "px";
            }
        </script>当他滚动到一定程度,差不多接近底部的时候 div 就不随着动 啦
      

  4.   

    是的啊,你的是绝对底部啦。
    这个也是啊 document.body.scrollTop + document.body.clientHeight- document.getElementById("div1").offsetHeight
      

  5.   

    得到div的底部坐标,和窗口的坐标比较。
      

  6.   

     if (scrollTop <= clientHeight)
    就是不行。。
    还差85px 就到底部。。请问有什么判断方法啊?大侠。。
      

  7.   

    http://www.narutom.com/
    这个里面的是好好的。。
    得到div的底部坐标,窗口坐标怎样得到?
    我先回家麻烦你解释下
      

  8.   

    看看这篇文章基本就可以了。
    http://www.blabla.cn/js_kb/javascript_pagesize_windowsize_scrollbar.html
      

  9.   


    <html xmlns="http://www.w3.org/1999/xhtml">
    <head >
        <title>无标题页</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div id='div2009_2010' style="position: absolute; bottom: 0; right: 5px; width: 240px; height: 165px;">
        <span style=" float:right; width:100%; text-align:right; position:absolute;">  <a href="javascript:void(0);" style=" color:Yellow; font-weight:bold;"  onclick='javascript:parentElement.parentElement.style.display="none";' >关闭 X</a></span>
            <a href="/2009-2010/2009-2010meeting.html" target="_blank">
                <img src='2009-2010/rb2.jpg' alt='' /></a>
        </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 />
        <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 />
        </form>    <script language="JavaScript">
            var s = "";
            s += "\r\n网页可见区域宽:" + document.body.clientWidth;
            s += "\r\n网页可见区域高:" + document.body.clientHeight;
            s += "\r\n网页可见区域宽:" + document.body.offsetWidth + " (包括边线和滚动条的宽)";
            s += "\r\n网页可见区域高:" + document.body.offsetHeight + " (包括边线的宽)";
            s += "\r\n网页正文全文宽:" + document.body.scrollWidth;
            s += "\r\n网页正文全文高:" + document.body.scrollHeight;
            s += "\r\n网页被卷去的高:" + document.body.scrollTop;
            s += "\r\n网页被卷去的左:" + document.body.scrollLeft;
            s += "\r\n网页正文部分上:" + window.screenTop;
            s += "\r\n网页正文部分左:" + window.screenLeft;
            s += "\r\n屏幕分辨率的高:" + window.screen.height;
            s += "\r\n屏幕分辨率的宽:" + window.screen.width;
            s += "\r\n屏幕可用工作区高度:" + window.screen.availHeight;
            s += "\r\n屏幕可用工作区宽度:" + window.screen.availWidth;
            s += "\r\n你的屏幕设置是 " + window.screen.colorDepth + " 位彩色";
            s += "\r\n你的屏幕设置 " + window.screen.deviceXDPI + " 像素/英寸";
            //alert(s); 
        </script>
        <script type="text/javascript">
            function getPost(ele) {
                var x = 0;
                var y = 0;
                var height = ele.offsetHeight;
                var width = ele.offsetWidth;
                if (ele.offsetParent) {
                    while (ele.offsetParent) {
                        x += ele.offsetLeft;
                        y += ele.offsetTop;
                        ele = ele.offsetParent;
                    }
                    return [x, x + width, y, y + height]
                }
                else {
                    return [ele.x, ele.x + width, ele.y, ele.y + height];
                }
            }
            window.onscroll = movepeixun;
            function movepeixun() {
                var sz = GetPageSize();
                var scrollHeight = parseInt(document.body.scrollHeight);
                var div = document.getElementById("div2009_2010");
                if (div) {
                    var pos = getPost(div);
                    var sl = GetPageScroll();
                    if ((sl.Y + parseInt(sz.WinH) - div.offsetHeight) >= scrollHeight) {
                        return;
                    }
                    div.style.top = sl.Y + parseInt(sz.WinH) - div.offsetHeight + "px";
                }
            }
            window.onresize = window.onscroll;
            window.scroll();
        </script>    <script type="text/javascript">
            function GetPageSize() {
                var scrW, scrH;
                 if (window.innerHeight && window.scrollMaxY) {    // Mozilla   
                    scrW = window.innerWidth + window.scrollMaxX; scrH = window.innerHeight + window.scrollMaxY;
                } else if (document.body.scrollHeight > document.body.offsetHeight) {    // all but IE Mac   
                    scrW = document.body.scrollWidth; scrH = document.body.scrollHeight;
                } else if (document.body) { // IE Mac  
                    scrW = document.body.offsetWidth; scrH = document.body.offsetHeight;
                } var winW, winH; if (window.innerHeight) { // all except IE   
                    winW = window.innerWidth; winH = window.innerHeight;
                } else if (document.documentElement && document.documentElement.clientHeight) {    // IE 6 Strict Mode   
                    winW = document.documentElement.clientWidth; winH = document.documentElement.clientHeight;
                } else if (document.body) { // other
                    winW = document.body.clientWidth; winH = document.body.clientHeight;
                }  // for small pages with total size less then the viewport
                var pageW = (scrW < winW) ? winW : scrW;
                var pageH = (scrH < winH) ? winH : scrH; 
                return { PageW: pageW, PageH: pageH, WinW: winW, WinH: winH };
            }
            //var sz = GetPageSize(); alert([sz.PageW, sz.PageH, sz.WinW, sz.WinH].join(", "));
            function GetPageScroll() {
                var x, y; if (window.pageYOffset) {    // all except IE  
                    y = window.pageYOffset; x = window.pageXOffset;
                } else if (document.documentElement && document.documentElement.scrollTop) {    // IE 6 Strict
                    y = document.documentElement.scrollTop; x = document.documentElement.scrollLeft;
                } else if (document.body) {    // all other IE   
                    y = document.body.scrollTop; x = document.body.scrollLeft;
                } return { X: x, Y: y };
            }    </script></body>
    </html>
      

  10.   

    这是整体页面的代码。。但是在傲游里面多滚动几次 这个div 就会丢失。
    说找不到对象。。
    请问这是什么回事?
    首先谢谢
    IBM_hoojo