How can I make fancyBox 2 adjust its height to fit

2020-04-05 08:00发布

I'm trying to get my fancyBox to 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.

I'm just using inline content, not an iframe. These are the options I set:

$('.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.

3条回答
我想做一个坏孩纸
2楼-- · 2020-04-05 08:17

Should anybody look for the solution for an iframe, use:

parent.jQuery.fancybox.update();
查看更多
太酷不给撩
3楼-- · 2020-04-05 08:22

Sounds a bit wierd. an ugly solution is to use css, overflow:hidden;

Whenever I use fancybox, the scrollbars work correctly. sure that the content oc the fancybox is not setting another height?

Edit: Viewed your example-site. Seems like there is some width beeing set in the content that is larger than the fancybox itself.

查看更多
爷的心禁止访问
4楼-- · 2020-04-05 08:29

Boolean and integer values should go without quotes 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.

查看更多
登录 后发表回答