Skip to content

Instantly share code, notes, and snippets.

@goyuix
Last active December 16, 2015 00:59
Show Gist options
  • Save goyuix/5351475 to your computer and use it in GitHub Desktop.
Save goyuix/5351475 to your computer and use it in GitHub Desktop.
Sample script to page in multiple blog pages for easier scrolling
// add in jQuery if it is not loaded
if (!window.jQuery) {
var script = document.createElement('script');
script.type="text/javascript";
script.src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js";
document.getElementsByTagName("head")[0].appendChild(script);
}
function getPosts(page) {
if (window.jQuery == undefined) { return setTimeout(function(){getPosts(page);},100); }
$.get("/page/"+page, function(d) {
$("#contentArea").append($(d).find("#contentArea > div.post"));
if (page+1 < 20) { getPosts(page+1); }
});
}
if (window.jQuery == undefined) {
setTimeout(function(){getPosts(2);}, 1000);
} else {
getPosts(2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment