2015-06-05 6 views
1

Как определить, прокручивается ли div в нижней части экрана с помощью функции нажатия кнопки (а не кнопки со стрелками)?Обнаруживать при прокрутке вниз

E.g .: Так, когда нажата кнопка $('#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"); 
    } 
}); 
Смежные вопросы