public
Last active

FB: Canvas - Scroll To Top

  • Download Gist
facebook.scrollTop.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
// Function for returning the user to any 'y' position in a Facebook app/tab. Uses jQuery animate, otherwise gracefully falls-back without it.
// Source[1]: http://stackoverflow.com/questions/7193425/how-do-you-animate-fb-canvas-scrollto
// Source[2]: https://developers.facebook.com/docs/reference/javascript/FB.Canvas.scrollTo/
 
var scrollY = function (y) {
if (window.jQuery) {
FB.Canvas.getPageInfo (function (pageInfo) {
$({ y: pageInfo.scrollTop })
.animate({
y: y
},
{
duration: 1000,
step: function (offset) {
FB.Canvas.scrollTo(0, offset);
}
});
});
} else {
FB.Canvas.scrollTo(0, y);
}
};

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.