2013-10-21 53 views
1

的底部我有一個表,我做到了滾動做溢出:汽車; 現在我想知道垂直滾動條是否到達底部,這樣我就可以顯示下一個5頁的頁面加載時隱藏的行。 哪裏我在網上搜索它使用window.height()....但我不需要使用窗口,因爲我的元素被限制在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(); 
     } 
    }); 
}); 
+0

$( 「#mailServerTbody」)[0 ] .scrollHeight –

+0

試$( 「#mailServerTbody表:最後的」),或者找到更多的http://stackoverflow.com/questions/9979418/how-to-find-last-child -of-特定型表使用,jquery的 – anshuVersatile

+0

@ WillemD'haeseleer'document.querySelector( '#mailServerTbody')。scrollHeight' – hitautodestruct

回答

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

它不工作heightOfTbody始終是未來零「0」 –

+0

您遵循相同的結構權$(「#mailServerTbody TR」),即 TBODY TR裏面有嗎? 我創建了一個JS提琴請參閱 http://jsfiddle.net/Shinov/229wE/ –

+0

其實我的TR的生成運行時..最初我TBODY是空.. 這可能是問題? –