Car*_*son 13 facebook scrollto facebook-javascript-sdk
我创建了一个设置大小(大约2,000像素高)的应用程序,并有一个调用FB.Canvas.scrollTo的菜单,以帮助用户导航长页面.
有没有办法添加平滑的滚动效果?Facebook没有在其开发者博客上提供任何解决方案.
Dav*_*ave 47
使用@ Jonny的方法,您可以更简单地使用
function scrollTo(y){
FB.Canvas.getPageInfo(function(pageInfo){
$({y: pageInfo.scrollTop}).animate(
{y: y},
{duration: 1000, step: function(offset){
FB.Canvas.scrollTo(0, offset);
}
});
});
}
Run Code Online (Sandbox Code Playgroud)
今天遇到了同样的问题 - 我想出了一些javascript,它利用jQuery的animate方法提供了一些缓动 - 滚动仍然是一个触摸生涩(我猜这是因为FB.Canvas.scrollTo代理).无论如何,这里是片段:
function scrollToTop() {
// We must call getPageInfo() async otherwise we will get stale data.
FB.Canvas.getPageInfo(function (pageInfo) {
// The scroll position of your app's iFrame.
var iFrameScrollY = pageInfo.scrollTop;
// The y position of the div you want to scroll up to.
var targetDivY = $('#targetDiv').position().top;
// Only scroll if the user has scrolled the window beneath the target y position.
if (iFrameScrollY > targetDivY) {
var animOptions = {
// This function will be invoked each 'tick' of the animation.
step: function () {
// As we don't have control over the Facebook iFrame we have to ask the Facebook JS API to
// perform the scroll for us.
FB.Canvas.scrollTo(0, this.y);
},
// How long you want the animation to last in ms.
duration: 200
};
// Here we are going to animate the 'y' property of the object from the 'iFrameScrollY' (the current
// scroll position) to the y position of your target div.
$({ y: iFrameScrollY }).animate({ y: targetDivY }, animOptions);
}
});
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8073 次 |
| 最近记录: |