如何在运行时调整 Fancybox 的大小?
有谁知道如何在运行时调整 jQuery Fancybox 的大小?
初始化 fancybox 时,我可以这样做:
$("tag").fancybox({ 'frameWidth': 500, 'frameHeight': 700 });
我用动态内容填充 fancybox,并希望它根据内容调整大小。
Does anyone know how to resize the jQuery Fancybox during runtime?
When initializing the fancybox I can do this:
$("tag").fancybox({ 'frameWidth': 500, 'frameHeight': 700 });
I am filling the fancybox with dynamic content and I want it to resize according to the content.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(18)
使用:
Use:
如果你使用的是Fancybox 1.3版本,有一个调整大小的方法:
对于 Fancybox 的 2.x 版本,执行相同操作:
它将根据活动的 fancybox 内部内容的大小调整其大小。
If you are using version 1.3 of Fancybox, there is a resize method:
For version 2.x of Fancybox the same would be done with:
Which will resize the active fancybox based on the size of the content inside it.
Alan 的解决方案是不完整的,因为修改大小后框不再位于屏幕中心(至少对于最新的 jquery 和 fancybox 版本)。
所以,完整的解决方案是:
Alan's solution is incomplete because the box is no longer centered on the screen after modifying the size (at least with the latest jquery and fancybox versions).
So, the complete solution would be:
$("#fancybox-wrap").width(宽度); //或者高度或者其他
$.fancybox.center();
$("#fancybox-wrap").width(width); //or height or whatever
$.fancybox.center();
嘿,经过近两天的战斗,我设法改变了覆盖高度。 希望这会有所帮助:
这段代码所做的是,它首先计算身体高度、#fancybox-content 和 #fancybox-overlay。 然后检查body的高度是否小于overlay的高度,如果是,则将新计算的高度分配给overlay,否则采用默认body的高度
Hey after fighting almost two days, I managed to change overlay height. Hope this can be helpful :
What this code doing is, it first calculate height of body, #fancybox-content and #fancybox-overlay. Then it check whether body's height is less than overlay's height, if yes then it assign new calculated height to overlay otherwise it take default body's height
我只是想让你意识到这一点。
在寻找使用 javascript 调整高度的解决方案后,我和我的伙伴发现了一些令人惊叹的事情。
检查 #fancybox-inner 的包含元素是否设置了 PADDING 或 MARGIN。
这是关键元素(#fancybox-inner margin/padding 定义的直接子元素。
子元素(#fancyfox-inner > div > .here)可以有填充,但不要忘记调整:
I just want to make you be aware of it.
After searching for solutions using javascript to adjust height me and my partner realized something stunning.
Check whether the containing elements of #fancybox-inner has PADDING or MARGIN set.
This is the key element (direct children of #fancybox-inner margin/padding definition.
The children elements (#fancyfox-inner > div > .here) can have padding, but dont forget to adjust:
在谷歌搜索了很长时间但没有找到任何东西后,我确实找到了这个错误的解决方案。
要将框的大小调整为页面的宽度和高度并将其居中,请执行以下操作:
I did find one solution to this bug after searching for it a long time in Google but not finding anything.
To resize the box to the width and height of the page and center it, do this:
如果Fancybox是jQuery UI的一部分,你会这样做:
但由于它似乎没有提供这样的方法,你需要直接设置CSS:
If Fancybox was part of jQuery UI, you'd do it like this:
But as it doesn't seem to provide such a method, you need to set the CSS directly:
并在需要时在事件上调用它...(例如 uploadify onSelect 事件 -> 长文件列表使 fancybox 如此大,我们再次计算高度)
and call it on event when you need... (eg. uploadify onSelect event -> long file list makes fancybox so big, and we calculate height again)
$.fancybox.resize(); 对我来说不起作用,所以我将此代码放入加载的页面中,在 fancybox iframe 内:
您也可以在回调中设置它:
$.fancybox.resize(); did not work for me, so I've put this code into the loaded page, inside the fancybox iframe :
You could also set it in a callback :
我也很难调整 fancybox 的大小。
解决方案是
$.fancybox.reposition();
非常有效!
I struggled with resizing fancybox too.
Solution is
$.fancybox.reposition();
Works like a charm!
我的解决方案是这样的(对于 fancybox 1.3.4):
查找
并替换为
My solution was like that (for fancybox 1.3.4):
find
and replace with
这个方法对我有用。 :)
This method works for me. :)
我刚刚在其 Google 群组 https://groups.google 上发布了 Fancybox 的建议补丁.com/forum/#!topic/fancybox/fuUuBJyTrH8 添加公共方法 $.fancybox.reshow()。 这将重新计算 fancybox 的高度和宽度。 它适用于 window.onorientationchange 和 window.onresize,例如:
I just posted a suggested patch to Fancybox on its Google Group https://groups.google.com/forum/#!topic/fancybox/fuUuBJyTrH8 that adds a public method $.fancybox.reshow(). This will recalculate the height and width of the fancybox. It works with both window.onorientationchange and window.onresize, for example:
这是我的解决方案:
This is the solution form my:
感谢所有为 StackOverflow.com 做出贡献的人。 你们多次成为我的救星。 现在,我终于可以做出一些贡献了。 下面是我如何克服运行时调整 fancybox 大小的困惑:
我分配了 href 元素特定属性,并将维度 PHP 变量传递给它。
然后在点击事件中调用并设置属性,其中嵌入了 fancybox 控制函数和参数......
Thanks to everyone who contributes to StackOverflow.com. You all have been life-savers to me many times over. Now, I finally get to contribute something. Below is how I was able to over come the resize fancybox at runtime quandry:
I assigned the href element specific attributes with dimension PHP vars passed to it.
Then called and set the attribute in a click-event, with the fancybox control function and parameters embedded within...
就我而言,我使用 Fancybox 来显示一个非常简单的网页,其中仅包含图像。 该图像的大小可能有所不同。 我的问题是图像不包含
style="height: NNpx; width: NNpx;"
。 如果没有这个,fancybox autoSize可能会给出意想不到的结果(在他们的文档http://fancyapps.com/fancybox/ ).tl;dr:提供宽度和高度属性,以便 autoSize 正常工作。
In my case, I'm using Fancybox to display a very simple web page that just contains an image. This image could vary in size. My problem was that the image didn't include
style="height: NNpx; width: NNpx;"
. Without that, the fancybox autoSize may give unexpected results (stated in their docs http://fancyapps.com/fancybox/ ).tl;dr: provide width and height attributes for autoSize to work correctly.
关于Fancybox 3(最新版本)
参考: http://fancyapps.com/fancybox/3/docs/#iframe
On Fancybox 3 (newest version)
Ref: http://fancyapps.com/fancybox/3/docs/#iframe