Skip to content

Instantly share code, notes, and snippets.

@bresson
Forked from adamcbrewer/facebook.scrollTop.js
Created March 14, 2013 16:43
Show Gist options
  • Save bresson/5162917 to your computer and use it in GitHub Desktop.
Save bresson/5162917 to your computer and use it in GitHub Desktop.
// 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);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment