var item_page = 1; // Page of items
var items_per_page = 10; // Items per page
var cancel_request = false; // Cancel request flag
var stop_scroll = false; // Stop scroll flag
function getItems(page) {
if (cancel_request === false) {
$.getJSON('http://search.twitter.com/search.json?q=star%20wars&rpp=' + items_per_page + '&page=' + page + '&include_entities=1&result_type=mixed&callback=?', function(data) {
// Query server for items
$.each(data.results, function(index) {
$('<li>' + data.results[index].text + '</li>').appendTo("#lazy_list");
});
// Turn off requests if current result set is less than page min
if ($(data.results).length < items_per_page) {
cancel_request = true;
}
// Show message if no items
if ($(data.results).length === 0) {
$(".no_results").show();
}
}).success(function() {
// Success
item_page++; // Increment page value
$(".loading").hide(); // Hide loading screen
stop_scroll = false; // Restart scroll
}).error(function() {
// Error
});
} else {
// Hide loading screen
$(".loading").hide();
}
}
$(document).ready(function() {
// Load initial page of tweets on load
getItems(item_page);
// Stop everything if no more requests
if (cancel_request === false) {
// Window scroll event
$(window).scroll(function() {
// Check if scroll is stopped to avoid multiple requests of the same page
if (!stop_scroll) {
// If user scrolls to the bottom of the page, grab the next page of tweets
if (($(window).scrollTop() + 100) >= ($(document).height() - $(window).height())) {
// Bottom of screen
stop_scroll = true; // Stop scroll event
...
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.