Fancybox 在 Facebook Canvas iFrame 中定位
好的,我有一个 iframe 画布应用程序,其高度设置为“可设置”,并且 facebook javascrip sdk 调用 FB.Canvas.setSize(); 和 FB.Canvas.setAutoGrow(); 。这些工作完美,因为 iframe 根据其内容设置为特定的像素高度。
问题是,当我调用 Fancybox 时,它会根据这个高度自行定位。我知道这正是它应该做的,因为 fancybox jQuery 通过以下方式返回视口:(
最新版本 jquery.fancybox-1.3.4.js 的第 673 行):
_get_viewport = function() {
return [
$(window).width() - (currentOpts.margin * 2),
$(window).height() - (currentOpts.margin * 2),
$(document).scrollTop() + currentOpts.margin
];
},
但问题是 iframe 将对于很多观众来说,比他们的浏览器窗口要长。因此,Fancybox 位于 iframe 的中心,最终大多数观众只能部分看到。 (即 iframe 高度为 1058px,而用户浏览器的高度仅为 650px)。
有没有办法让 fancybox 只计算物理浏览器高度?或者我是否需要更改 Facebook 画布应用程序中的某些设置才能使其正常工作?
我喜欢 Facebook 上唯一的滚动条(父滚动条,如果你愿意的话)。
非常感谢所有建议!
OK so I have a iframe canvas app with its height set to "Settable" with the facebook javascrip sdk calls to FB.Canvas.setSize(); and FB.Canvas.setAutoGrow();. These are working perfectly, as the iframe gets set to a certain pixel height based on its content.
The problem is that when I make a call to Fancybox, it positions itself based on this height. I know that's exactly what its supposed to do as the fancybox jQuery returns the viewport by:
(line 673 of latest version of jquery.fancybox-1.3.4.js):
_get_viewport = function() {
return [
$(window).width() - (currentOpts.margin * 2),
$(window).height() - (currentOpts.margin * 2),
$(document).scrollTop() + currentOpts.margin
];
},
But the problem is the iframe will, for a lot of viewers, be longer than their browser window. So the Fancybox centers itself in the iframe and ends up only partly visible to the majority of viewers. (i.e. iframe height is 1058px and users browser is say only 650px).
Is there a way to have fancybox just calculate the physical browser height? Or do I need to change some settings in my Facebook canvas app to make it work?
I like how the only scrollbar is the one on Facebook (the parent, if you will).
All suggestions GREATLY appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
对于 fancybox 2 尝试:
find:
并替换为:
然后在函数 getViewport 中将 return rez; 替换为:
最后在 _getPosition 函数中替换行:
和:
For fancybox 2 try:
find:
and replace with:
Then in function getViewport replace return rez; with:
and finally in _getPosition function replace line:
with:
由于facebook js api提供了页面信息,那么我们就可以使用它,所以
找到
replace with
并修改_get_viewport函数
As facebook js api provides page info, then we could use it, so
find
replace with
and also modify _get_viewport function
我遇到了同样的问题,我使用了“centerOnScroll”:true,现在它工作正常......
I had the same problem, i used 'centerOnScroll' :true, and now it works fine...
有同样的问题。值得庆幸的是 fancybox 可以通过 CSS 访问。我的解决方案是覆盖 fancybox 在 CSS 文件中的定位:
此代码将 fancybox 始终放置在距 iframe 顶部 20px 的位置。如果您愿意,可以使用不同的尺寸。即使 fancybox 在运行时动态设置位置,!important 也会设置此定位。
Had the same problem. Thankfully fancybox is accessable through CSS. My solution was to overwrite fancybox's positioning in my CSS file:
This code places the fancybox always 20px from top of the iframe. Use a different size if you like. The !important sets this positioning even though fancybox sets the position dynamically at runtime.
这是一种方法,通过相对于另一个元素的位置定位 Fancybox,在我的例子中,上传队列完整的 div 在用户上传图像后显示视图链接。
有一个带有设置 ID 的样式块,如下所示:
然后打开 Fancybox 的链接调用具有图像名称、宽度和高度的函数来设置内容和大小。重要的部分是定位。通过获取队列完整 div 的位置,生成一个新的类声明(fancy-position),在 fancybox 加载之前将其附加到样式块(!类中的重要将覆盖 fancybox 中的定位),然后使用fancybox选项中的wrapCSS参数,它将fancybox准确地定位在我想要的位置。
Here's one way to do it by positioning the Fancybox relative to the position of another element, in my case an Uploadify queue complete div that displays a view link after the user uploads an image.
Have a style block with a set ID like so:
Then the link to open the Fancybox calls a function with the image name, width, and height to set the content and sizes. The important part is the positioning. By getting the position of the queue complete div, generating a new class declaration (fancy-position), appending it to the style block BEFORE the fancybox loads (!important in class will override positioning from fancybox), then adding the new class using the wrapCSS parameter in the fancybox options, it positions the fancybox exactly where I want it.