Home >Web Front-end >JS Tutorial >How to Detect When a User Has Reached the Bottom of a Div with Variable Content Using jQuery?
Detecting End of Div Scrolling with jQuery
Objective:
Determine when a user scrolls to the bottom of a specified div element.
Question:
How can I detect when a user reaches the bottom of a div with a variable amount of content and overflow set to auto?
Answer:
To detect the end of div scrolling, use the following jQuery properties/methods:
Combine the first two properties to get the total visible height, and compare it to the scrollHeight to determine when the user has scrolled to the bottom.
<code class="javascript">jQuery(function($) { $('#flux').on('scroll', function() { if($(this).scrollTop() + $(this).innerHeight() >= $(this)[0].scrollHeight) { alert('End of div reached'); } }) });</code>
Additional Notes:
The above is the detailed content of How to Detect When a User Has Reached the Bottom of a Div with Variable Content Using jQuery?. For more information, please follow other related articles on the PHP Chinese website!