我有一个表格,我通过执行溢出使其可滚动: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();
}
});
});
最佳答案
试试这个
<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>
关于javascript - 如何知道我到达了表格底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19487174/