2014-10-23 4 views
-1

У меня есть 5 элементов div с разной высотой. Пример:Как обнаружить прокрутку браузера до конца каждого элемента?

<body> 
    <div id="d1" style="height: 800px; float: left; width:100%;"></div> 
    <div id="d2" style="height: 920px; float: left; width:100%;"></div> 
    <div id="d3" style="height: 876px; float: left; width:100%;"></div> 
    <div id="d4" style="height: 1200px; float: left; width:100%;"></div> 
    <div id="d5" style="height: 1105px; float: left; width:100%;"></div> 
</body> 

Минимальная высота div равна высоте окна.

Как определить, когда пользователь прокручивает нижнюю часть каждого элемента?

Спасибо,

ответ

1

решение JQuery (в прокрутки слушателя событий)

var winHeight = $(window).height(); 
if ($(document).scrollTop() >= $('#d5').offset().top + $('#d5').height() - winHeight) { 
    // scrolled to the bottom of d5 div. 
} else if ($(document).scrollTop() >= $('#d4').offset().top + $('#d4').height() - winHeight) { 
    // scrolled to the bottom of d4 div. 
} else if ($(document).scrollTop() >= $('#d3').offset().top + $('#d3').height() - winHeight) { 
    // scrolled to the bottom of d3 div. 
} else if ($(document).scrollTop() >= $('#d2').offset().top + $('#d2').height() - winHeight) { 
    // scrolled to the bottom of d2 div. 
} else if ($(document).scrollTop() >= $('#d1').offset().top + $('#d1').height() - winHeight) { 
    // scrolled to the bottom of d1 div. 
} 
Смежные вопросы