怎么知道我到达桌子底 [英] how to know i reached bottom of table

查看:76
本文介绍了怎么知道我到达桌子底的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a table and i made it scrollable by doing overflow : auto; Now i want to know if the vertical scroll bar reached the bottom so that i can display next 5 row which were hidden on page load. Where ever i searched the internet it uses window.height() .... but i dont need to use window as my element is restricted to a table in a 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中做的事情

here is what i am trying to do in 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();
        }
    });
});

推荐答案

尝试一下

<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>

这篇关于怎么知道我到达桌子底的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆