2

So far I can alert the "scrollTop"-value of "FB.Canvas.getPageInfo":

FB.Canvas.getPageInfo(
      function(info) {
          alert('scrollTop: ' + info.scrollTop);
      }
  );

Now I would like to use this value in one of my functions, but I don't know how. The following is not working:

function test() {
    var fbScrollTop = FB.Canvas.getPageInfo();
    alert(fbScrollTop);
}

How can I access the the value?

CRABOLO
  • 8,605
  • 39
  • 41
  • 68
chris
  • 2,109
  • 2
  • 23
  • 33

3 Answers3

1

I don't know if it's useful yet. But now I can center my divs in my facebook app. Here is the function:

jQuery.fn.center = function () {
    var temp = this;
    FB.Canvas.getPageInfo(
    function(info) {
            $(temp).css("position","absolute");
            $(temp).css("top", Math.max(0, ((info.clientHeight - $(temp).outerHeight()) / 2) + info.scrollTop) + "px");
            $(temp).css("left", Math.max(0, ((info.clientWidth - $(temp).outerWidth()) / 2) + info.scrollLeft) + "px");
        }
    );

    return this;
}

And I use like that:

var loading = $("#loading");
    loading.center();
Rodrigo
  • 188
  • 1
  • 8
0

Just combine both

function test() {
    var fbScrollTop;
    FB.Canvas.getPageInfo(function(info) {
        fbScrollTop = info.scrollTop;
        alert(fbScrollTop);
    });
}
Alexander Nenkov
  • 2,910
  • 20
  • 28
0

Most of the methods available in the SDK are asynchronous - this means that the response will not be available until the provided callback is invoked (with the response).

Sean Kinsey
  • 37,689
  • 7
  • 52
  • 71