javascript 如何让fancyBox 2 调整其高度以适合其内容?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16272517/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I make fancyBox 2 adjust its height to fit its contents?
提问by Chris
I'm trying to get my fancyBoxto expand in height when its contents are taller than the viewport. That way, the user scrolls its contents using the browser's scroll bar. Instead, my fancyBox keeps getting its own scroll bar.
当它的内容比视口高时,我试图让我的FantasyBox在高度上扩展。这样,用户就可以使用浏览器的滚动条滚动其内容。相反,我的fancyBox 一直有自己的滚动条。
I'm just using inline content, not an iframe
. These are the options I set:
我只是使用内联内容,而不是iframe
. 这些是我设置的选项:
$('.fancybox').fancybox({
autoSize: 'false',
fitToView: 'false',
maxWidth: 940
});
Adding scrolling: 'no'
cuts off the content at the bottom. Explicitly defining a really tall height works, but I want the height to be determined dynamically.
添加会scrolling: 'no'
切断底部的内容。明确定义一个非常高的高度是可行的,但我希望动态确定高度。
采纳答案by JFK
Boolean and integer values should go withoutquotes so this
布尔值和整数值应该没有引号,所以这个
$('.fancybox').fancybox({
autoSize: 'false',
fitToView: 'false',
maxWidth: 940
});
should be
应该
$('.fancybox').fancybox({
autoSize: false, // shouldn't be true ?
fitToView: false,
maxWidth: 940
});
fitToView
is actually the option that gives you what you need but the quoted "false"
didn't make it work for you. On the other hand, I am not sure you should disable autoSize
because otherwise the inline
content won't get its own height.
fitToView
实际上是为您提供所需内容的选项,但引用的内容"false"
并不适合您。另一方面,我不确定您是否应该禁用autoSize
,否则inline
内容将不会获得自己的高度。
回答by Arjan
Should anybody look for the solution for an iframe, use:
如果有人寻找iframe的解决方案,请使用:
parent.jQuery.fancybox.update();
回答by John
Sounds a bit wierd. an ugly solution is to use css, overflow:hidden;
听起来有点怪。一个丑陋的解决方案是使用 css, overflow:hidden;
Whenever I use fancybox, the scrollbars work correctly. sure that the content oc the fancybox is not setting another height?
每当我使用fancybox 时,滚动条都能正常工作。确定fancybox 的内容没有设置另一个高度?
Edit: Viewed your example-site. Seems like there is some width beeing set in the content that is larger than the fancybox itself.
编辑:查看您的示例站点。似乎在内容中设置了一些比fancybox本身大的宽度。