2015-01-13 18 views
2

所以這裏是我的網頁發現哪些元素(DIV)已被證明在一個頁面滾動條

<Style>.item{ width :200px ; height:200px ; background-color:red ; float:right ; margin : 10px}</style> 

<div class="item"></div> 
<div class="item"></div> 
<div class="item"></div> 
<div class="item"></div> 

這裏是完整的代碼

http://jsfiddle.net/gup3o1ap/1/

,你可以看到有頁面上有很多div.item和頁面有一個大滾動條,我想知道哪些.item已被用戶看到,所以基本上我需要知道頁面上可見的最後一個項目(.items之前有已經顯示)

這樣我就可以計算出,當滾動到達的頁面

$(window).scroll(function() { 

    if($(window).scrollTop() + $(window).height() > $(document).height() - 200) { 
     console.log('at the end'); 
    } 
}); 

結束,但我不知道我怎樣才能找到哪個元素是頁面

+0

你的小提琴似乎在爲我工作:http://jsfiddle.net/hyuf929k/它在底部時發出警報? –

+0

@SimonStaton我想知道哪個元素是頁面上顯示的最後一個元素,而不是當滾動到達頁面底部時 – max

回答

0

http://api.jquery.com/scrolltop/

上顯示的最後一個

scrollTop()爲您提供頁面上方的高度,因此您可以將它與元素高度和窗口高度一起使用(並進行一些數學運算)以查找顯示的元素。