调整 jQuery Fancybox' iframe高度根据里面内容的变化动态变化

发布于 2024-12-04 14:44:50 字数 580 浏览 3 评论 0原文

我正在使用 jQuery Fancybox 在模式窗口中显示表单。我使用以下代码:

$("a.iframe").fancybox({
'padding': 0,
'width': 650,
'showCloseButton': false,
'hideOnContentClick': false,
'transitionIn': 'elastic',
'transitionOut': 'elastic',
'onComplete': function () {
  $('#fancybox-frame').load(function () {
    $('#fancybox-content').height($(this).contents().find('body').height() + 20);
  });
}
});

通过附加的 onComplete 函数,我可以根据内部内容的高度调整 iframe 的高度。

但是,我在 iframe 中使用 jQuery 的 .hide() 隐藏了一些元素。每当我想要 .show() 这些元素时,iframe 本身不会随着现在可见元素的额外高度而调整大小。

我怎样才能做到这一点?谢谢!

I'm using jQuery Fancybox to display forms in a modal window. I'm using the following code:

$("a.iframe").fancybox({
'padding': 0,
'width': 650,
'showCloseButton': false,
'hideOnContentClick': false,
'transitionIn': 'elastic',
'transitionOut': 'elastic',
'onComplete': function () {
  $('#fancybox-frame').load(function () {
    $('#fancybox-content').height($(this).contents().find('body').height() + 20);
  });
}
});

With the additional onComplete function, I'm able to adjust the height of the iframe accordingly to the height of the contents inside.

However, I've hidden a few elements with jQuery's .hide() inside the iframe. Whenever I want to .show() these elements, the iframe itself doesn't resize along with the extra height of the now visible elements.

How can I accomplish this? Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

狼亦尘 2024-12-11 14:44:50

将下面的函数放到页面

$.fn.ResizeFancy = function(){
   $('#fancybox-content').height($('#fancybox-frame').contents().find('body').height() + 20);
};

后,触发这个函数到你的showHide函数中。例如;

function yourShowHideFn(){
    //bla bla bla

    $.fn.ResizeFancy();
}

Put the following function to the page

$.fn.ResizeFancy = function(){
   $('#fancybox-content').height($('#fancybox-frame').contents().find('body').height() + 20);
};

After, trigger this function to your showHide function. For example;

function yourShowHideFn(){
    //bla bla bla

    $.fn.ResizeFancy();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文