I've been following this example on jsFiddle: http://jsfiddle.net/jackdent/gRzPF/12/
...to automatically load more content when the user reaches the end of the currently displayed content. Unfortunately the example only seems to work when the .content div has a set height in pixels in the CSS.
How can I achieve the desired result without setting a height? I've got a tonne of information on a single page, broken up into several sections, that I want hidden before the users scrolls to it, at which point it appears.
Been looking at infinite scrolling plugins, but all the examples seem to only be for remote content. I basically need the same thing but for content on the one page. I'm only competent with HTML/CSS, I can insert jQuery and play around with values a little, but am otherwise terrible with it...
jQuery
//Set intital divs to be hidden
$(".content").addClass("noshow");
var contentNumber = 0;
function reveal() {
var constraintNumber = contentNumber + 6;
//IMPORTANT - DO NOT DELETE
$(window).trigger('resize');
//IMPORTANT - DO NOT DELETE
for (i = contentNumber; i < constraintNumber; i++) {
//Get the nth div of class content, where n is the contentNumber, and make it shown
$('.content').eq(contentNumber).removeClass("noshow");
contentNumber ++;
}
}
//Window scroll function
$(window).scroll(function() {
if ($(window).scrollTop() == $(document).height() - $(window).height() )
{
reveal();
}
});
reveal();
HTML
<div class="content">I have some content</div>
<div class="content">I have some content</div>
<div class="content">I have some content</div>
<div class="content">I have some content</div>
<div class="content">I have some content</div>
<div class="content">I have some content</div>
<div class="content">I have some content</div>
<div class="content">I have some content</div>
<div class="content">I have some content</div>
<div class="content">I have some content</div>
<div class="content">I have some content</div>
<div class="content">I have some content</div>
<div class="content">I have some content</div>
<div class="content">I have some content</div>
<div class="content">I have some content</div>
<div class="content">I have some content</div>
<div class="content">I have some content</div>
<div class="content">I have some content</div>
<div class="content">I have some content</div>
<div class="content">I have some content</div>
<div class="content">I have some content</div>
<div class="content">I have some content</div>
CSS
.content {
margin: 1px;
width: 200px;
height: 400px;
border: 1px solid black;
float: left;
background-color: gray;
}
.noshow{
display: none;
}