2015-06-05 140 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"); 
    } 
});