Centered dialog on Facebook canvas app

你说的曾经没有我的故事 提交于 2019-12-04 19:33:54

It looks like Facebook no longer poll the server to update the pageInfo as part of their library. However, it's fairly simple to write something that polls it yourself, and move the dialog appropriately:

var timeout;
var positionDialog = function(){
    FB.Canvas.getPageInfo(function(pageInfo){
         $("#dialog").animate({top: Math.max(parseInt(pageInfo.scrollTop) - parseInt(pageInfo.offsetTop) + 
            ((parseInt(pageInfo.clientHeight)-$("#dialog").outerHeight())/2), 0)}, 100);
         timeout = setTimeout(positionDialog, 250);
    });
};

var showDialog = function(){
    // show your dialog
    $("#dialog").show();
    positionDialog();
};

var hideDialog = function(){
    $("#dialog").hide();
    clearTimeout(timeout);
};

Note: I've used setTimeout rather than setInterval, as you don't know how long the ajax calls will take, and don't want to be handling out of order responses.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!