Skip to content

Instantly share code, notes, and snippets.

@seebz
Created October 17, 2012 07:59
Show Gist options
  • Save seebz/3904297 to your computer and use it in GitHub Desktop.
Save seebz/3904297 to your computer and use it in GitHub Desktop.
FB app page tab - infinite scroll
window.fbAsyncInit = function() {
FB.init({
appId : '<?php echo FB_APP_ID; ?>', // App ID
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
oauth : true, // enable OAuth 2.0
xfbml : true // parse XFBML
});
FB.Canvas.setAutoGrow();
FB.Canvas.scrollTo(0,0);
function getDocHeight() {
var D = document;
return Math.max(
Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
Math.max(D.body.clientHeight, D.documentElement.clientHeight)
);
}
setInterval(function() {
FB.Canvas.getPageInfo(function(pageInfo){
var documentHeight = getDocHeight();
var log = '';
for(var x in pageInfo)
log += '<b>' + x + '</b>: ' + pageInfo[x] + '<br />';
log += '<br />';
log += 'documentHeight: ' + documentHeight + '<br />';
var scrollTop2 = ( pageInfo.scrollTop - pageInfo.offsetTop );
log += 'scrollTop2 : ' + scrollTop2 + '<br />';
var clientHeight2 = ( pageInfo.clientHeight - pageInfo.offsetTop );
log += 'clientHeight2 : ' + clientHeight2 + '<br />';
log += ( documentHeight - clientHeight2 - pageInfo.scrollTop );
// #debug = div
$('#debug').html(log);
$('#debug').css('top', 100 + pageInfo.scrollTop);
if ( ( documentHeight - clientHeight2 - pageInfo.scrollTop ) < 0 )
{
// #lipsum = container
// #sample = content à ajouter
$('#lipsum').append( $('#sample').clone() );
}
});
}, 1000);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment