相关代码如下:<head runat="server">
    <title></title>
    <script type="text/javascript">
        function test() { alert('我开始滚动了'); return false; }  
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Panel ID="Panel1" runat="server" ScrollBars="Vertical" Width="500px" Height="70px" onscroll="test();">
            <div>
                test<br />
                test<br />
                test<br />
                test<br />
                test<br />
                test<br />
                test<br />
                test<br />
                test<br />
                test<br />
                test<br />
                test<br />
                test<br />
                test<br />
                test<br />
                test<br />
                test<br />
                test<br />
                test<br />
                test<br />
                test<br />
                test<br />
                test<br />
                test<br />
                test<br />
                test<br />
                test<br />
                test<br />
                test<br />
                test<br />
                test<br />
                test<br />
                test<br />
                test<br />
                test<br />
                test<br />
            </div>
        </asp:Panel>
    </div>
    </form>
</body>以上的panel被解析成div,这个div带有上下滚动条,我想问一下,如何通过onscroll事件判断滚动条已经被滚动到了最底部?

解决方案 »

  1.   

    <!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=utf-8" />
    <title>onscroll</title>
    <script type="text/javascript">
    function test() { 
       var panel = document.getElementById("Panel1");
       var scrollTop,maxScroll,minScroll=0;
       scrollTop = panel.scrollTop;
       maxScroll = panel.scrollHeight - panel.offsetHeight;
       if(scrollTop >= maxScroll){
           alert("滚动到底了");
       return false;
       }
       if(scrollTop <=0){
           alert("滚动到顶了");
       return false;
       }
    }
    </script>
    </head>
    <body>
        <div id="Panel1" style="width:500px;height:70px;overflow:auto;" onscroll="test();">
             <div> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br /> test<br />
             </div>
        </div>
    </body>
    </html>