2015-06-05 170 views
1

如何通過使用按鈕點擊功能(不滾動箭頭按鈕)來檢測div是否滾動到底部?檢測滾動到底部

例如:所以當點擊$('#checkBottom').時,如果$('#items')已滾動到div的底部,則會輸出警報。當點擊$('#checkBottom').時,如果$('#items')尚未滾動到div的底部,則不輸出警報。

JQ:

$('#checkBottom').on('click', function() { 
    alert("yes, it has reached the bottom of the scroll"); 
}); 

滾動DIV結構示例:

<div id="Wrapper"> 
    <div id="itemWrapper"> 
     <div id="items"> 
      <div class="content"> 
       <input type="image" src="http://img42.com/p1puE+" /> 
      </div> 
      <div class="content"> 
       <input type="image" src="http://img42.com/p1puE+" /> 
      </div> 
      <div class="content"> 
       <input type="image" src="http://img42.com/p1puE+" /> 
      </div> 
     </div> 
    </div> 
</div> 
+0

你是什麼意思由_scrolled到div_的底部?在視口上顯示還是不顯示? – lshettyl

+1

http://stackoverflow.com/questions/123999/how-to-tell-if-a-dom-element-is-visible-in-the-current-viewport – Anonymous

+0

##checkBottom'定位固定'? –

回答

2
$('#checkBottom').on('click', function() { 
    var wrapper = document.getElementById('Wrapper'); 
    if (wrapper.scrollTop + wrapper.offsetHeight >= wrapper.scrollHeight) { 
    alert("yes, it has reached the bottom of the scroll"); 
    } 
});