The code that I am currently using displays 4 divs at a time and loads 4 more divs when the user clicks on the "Load more" button.
<script>
$(function() {
$(".post").slice(0, 4).show();
$("#loadMore").on('click', function(e) {
e.preventDefault();
$(".post:hidden").slice(0, 4).slideDown();
if ($(".post:hidden").length == 0) {
$("#load").fadeOut('slow');
}
});
});
</script>
How would I edit this so that four new divs are automatically displayed when the user scrolls to the bottom of the parent div rather than clicking the button.
The first four divs that are loaded should be due to the user clicking on the button and from then on should load once the user scrolls to the bottom of the parent div.
<div class="contents">
<div class="post"></div>
<div class="post"></div>
<div class="post"></div>
<div class="post"></div>
<div class="post"></div>
<div class="post"></div>
<div class="post"></div>
<div class="post"></div>
<div class="post"></div>
<div class="post"></div>
<div class="post"></div>
<div class="post"></div>
<div class="post"></div>
<div class="post"></div>
<div class="post"></div>
</div>