<div id="scroll_guide"></div>
<div id="console"></div>
<h1>This is the results</h1>
<div id="result_wrapper">
<div class="block">Testing</div>
<div class="block">Testing</div>
<div class="block">Testing</div>
<p class="clear">.</p>
</div>
<div id="footer">This is the footer of the page</div>
var contentHeight = 250; // What is the height of the static content of the page?
var curPage = 1; // What virtual 'page' of results are we on?
var $console; // For showing debug info
// Show a console message
function log(msg) {
$console.append('<p>' + msg + '</p>');
$console.animate({
scrollTop: 99999
}, "fast"); // Scroll to bottom
}
// Calculate the height of the scroll target based on page content
function calcScrollTarget() {
var windowHeight = document.documentElement.clientHeight;
var bodyHeight = $(document).height();
var delta = bodyHeight - windowHeight - 50;
log('Scroll target: ' + bodyHeight + ' (body content) - ' + windowHeight + ' (browser height) - 50 (buffer) = ' + delta);
contentHeight = delta; // Update target amount
$('div#scroll_guide').height(delta); // Update guide
}
// Load the next page of content
function loadContent() {
if (curPage >= 7) {
// Cap results
contentHeight = 999999; // Move scroll target past end of page
} else {
// Simulate new results
// In reality this would be an AJAX call, likely
curPage++; // Next page
var $result = $('div#result_wrapper').append('<p>xxx ' + curPage + '</p>');
for (var i = 1; i <= 24; i++) {
$result.append('<div class="block">Page ' + curPage + ', number ' + i + '</div>');
}
$result.append('<p class="clear">.</p>');
calcScrollTarget(); // Update scroll target
}
}
$(document).ready(function() {
$console = $('div#console'); // Store for future use
// Create initial results
var $result = $('div#result_wrapper').html('');
for (var i = 1; i <= 24; i++) {
$result.append('<div class="block">Result ' + i + '</div>');
}
$result.append('<p class="clear">.</p>');
calcScrollTarget(); // Set initial scroll target
$(window).resize(calcScrollTarget); // If browser size changes, recalculate scroll target
// monitor the window's scroll event
$(window).scroll(function() {
//log("Scroll detected:...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.