Centered dialog on Facebook canvas app

感情迁移 提交于 2019-12-10 00:12:39

问题


How can I create a dialog that stays centered as the user scrolls through my Facebook canvas app?

I've read this post on the subject, but the method described there (listening to the undocumented facebook-event) did not work for me.


回答1:


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.



来源:https://stackoverflow.com/questions/11000073/centered-dialog-on-facebook-canvas-app

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