div处在一个初始位置,滚动条下拉,div的上端与浏览器接触,然后一直处于与浏览器接触状态,随页面而滚动。滚动条上拉到顶端,div回到初始位置。怎么做,哥哥们,网上资料不少,但是没有这个类型的。这个div悬浮框还要判断是否与浏览器接触,接触了再随浏览器移动,没接触不移动。

解决方案 »

  1.   

    楼主 这个意思?<!doctype html>
    <html>
    <head>
    <meta charset="gb2312" />
    <title>Test</title>
    <style>
    body { height:2000px; }
    #test { width:100px; height:100px; position:absolute; background:#ddd; }
    </style>
    <script>
    function $(o){return document.getElementById(o)}
    window.onload = function(){
    var obj = $('test');
    var objTop = obj.style.top;
    window.onscroll = function(){
    var iTop = document.documentElement.scrollTop;
    //alert(objTop)
    obj.style.top = !iTop ? objTop : iTop+'px';

    }
    }
    </script>
    </head>
    <body>
    <div id="test" style="top:300px; right:10px;"></div>
    </body>
    </html>