1

我有一张桌子,我通过溢出使它可以滚动:auto; 现在我想知道垂直滚动条是否到达底部,以便我可以显示在页面加载时隐藏的下 5 行。无论我在哪里搜索互联网,它都使用 window.height() .... 但我不需要使用 window,因为我的元素仅限于 iframe 中的表格。

这是表结构

 <div class="responsive" style="height:150px; overflow:hidden;" >
   <table class="responsive table table-bordered dataTable" id="checkAllEmail"  >
     <thead>
       <tr style="display:block;">
         <th class="serial" style="width:57px;">#</th>
         <th style="width:156px;">Display Name</th>
         <th class="tableButton" style=" text-align:center!important; width:147px;">Actions</th>
       </tr>
     </thead>
     <tbody id="mailServerTbody" style="height:113px; overflow:auto; display:block;">
     </tbody>
   </table>
 </div>

这是我在 js 中尝试做的事情

$(document).ready(function(){

var div=0;
 $('#mailServerTbody').scroll(function(){
        var temp = $(this).scrollTop();
        console.log($("#mailServerTbody").position().top+"blah")
        console.log(temp)
        if((temp%32==0)||(temp%32==17)){
            console.log("enter")
            div = div+4;
            //div = div*5-1;
            console.log(temp/32+"temp")
            $('#mailServerTbody tr:gt('+div+'):lt(5)').show();
        }
    });
});
4

1 回答 1

1

试试这个

<script type="text/javascript">
   $(document).ready(function(){
   var tbody = $('#mailServerTbody');
   var heightOfTbody = 0;
   $("#mailServerTbody tr").each(function(){
    heightOfTbody = heightOfTbody + $(this).height();
   });

   $('#mailServerTbody').scroll(function(){

   if(heightOfTbody == ($(this).scrollTop() + $('#mailServerTbody').height() ))
        {
       alert("reached last")
        }
   });
 });
</script>
于 2013-10-21T06:39:28.363 回答