Skip to content

Instantly share code, notes, and snippets.

@apfelbox
Forked from adamcbrewer/facebook.scrollTop.js
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apfelbox/a2cf3c234328b9a0e377 to your computer and use it in GitHub Desktop.
Save apfelbox/a2cf3c234328b9a0e377 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/
function scrollinFacebook (toY, duration) {
if (FB.Canvas.getPageInfo) {
FB.Canvas.getPageInfo (function (pageInfo) {
$({ y: pageInfo.scrollTop })
.animate({
y: toY
},
{
duration: duration,
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