1

How to detect if a div has scrolled to the bottom by using a button click function (not scroll arrow buttons)?

E.g.: So when $('#checkBottom'). is clicked, if $('#items') has scrolled to the bottom of the div it outputs the alert. And when $('#checkBottom'). is clicked, if $('#items') has not scrolled to the bottom of the div it dosen't output the alert.

Jq:

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

scroll div structure example:

<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>
Becky
  • 1
  • 9
  • 29
  • 64

1 Answers1

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");
  }
});
Samuli Hakoniemi
  • 16,628
  • 1
  • 55
  • 71