Skip to content

Instantly share code, notes, and snippets.

@influxweb
Created June 19, 2013 15:28
Show Gist options
  • Save influxweb/5815220 to your computer and use it in GitHub Desktop.
Save influxweb/5815220 to your computer and use it in GitHub Desktop.
Load content on scroll automatically Some websites such as Twitter loads content on scroll. Which means that all content is dynamically loaded on a single page as long as you scroll down. Here’s how you can replicate this effect on your website: http://www.catswhocode.com/blog/useful-jquery-code-snippets
var loading = false;
$(window).scroll(function(){
if((($(window).scrollTop()+$(window).height())+250)>=$(document).height()){
if(loading == false){
loading = true;
$('#loadingbar').css("display","block");
$.get("load.php?start="+$('#loaded_max').val(), function(loaded){
$('body').append(loaded);
$('#loaded_max').val(parseInt($('#loaded_max').val())+50);
$('#loadingbar').css("display","none");
loading = false;
});
}
}
});
$(document).ready(function() {
$('#loaded_max').val(50);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment