Last active
December 16, 2015 00:59
-
-
Save goyuix/5351475 to your computer and use it in GitHub Desktop.
Sample script to page in multiple blog pages for easier scrolling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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