【问题标题】:Content not sizing to modal window until browser window resize在浏览器窗口调整大小之前,内容不会调整到模态窗口
【发布时间】:2016-01-15 23:00:29
【问题描述】:

我正在尝试将动态内容放置在模式(弹出窗口)中,但它们的大小不正确。但是,如果我打开弹出窗口并调整浏览器窗口的大小,它们就会到位。在打开模式之前,内容的大小明显适合隐藏的 div。我怎样才能解决这个问题?我假设 jQuery 是要走的路?

下面是我所面临的屏幕截图。照片的顶部是当我单击链接打开模式时出现的内容,底部是在我调整窗口大小后发生的事情(这就是我所追求的)。

这是点击事件代码。

// Lightbox Link
            $(context).on('click', ThemifyGallery.config.lightbox, function(event){
                event.preventDefault();
                var $self = $(this),
                    $link = ( $self.find( '> a' ).length > 0 ) ? $self.find( '> a' ).attr( 'href' ) : $self.attr('href'),
                    $type = ThemifyGallery.getFileType($link),
                    $title = (typeof $(this).children('img').attr('alt') !== 'undefined') ? $(this).children('img').attr('alt') : $(this).attr('title'),
                    $iframe_width = (ThemifyGallery.isVideo($link)) ? '100%' : (ThemifyGallery.getParam('width', $link)) ? ThemifyGallery.getParam('width', $link) : '700',
                    $iframe_height = (ThemifyGallery.isVideo($link)) ? '100%' : (ThemifyGallery.getParam('height', $link)) ? ThemifyGallery.getParam('height', $link) : '100%';
                    if($iframe_width.indexOf("%") == -1) $iframe_width += 'px';
                    if($iframe_height.indexOf("%") == -1) $iframe_height += 'px';

                if( ThemifyGallery.isYoutube( $link ) ) {
                    // for youtube videos, sanitize the URL properly
                    $link = ThemifyGallery.getYoutubePath( $link );
                }
                var $args = {
                    items: {
                        src: $link,
                        title: $title
                    },
                    type: $type,
                    iframe: {
                        markup: '<div class="mfp-iframe-scaler" style="max-width: '+$iframe_width+' !important; height: '+$iframe_height+';">'+
                        '<div class="mfp-close"></div>'+
                        '<div class="mfp-iframe-wrapper">'+
                        '<iframe class="mfp-iframe" frameborder="0" allowfullscreen></iframe>'+
                        '</div>'+
                        '</div>'
                    }
                };
                if($self.find('img').length > 0) {
                    $.extend( $args, {
                        mainClass: 'mfp-with-zoom',
                        zoom: {
                            enabled: true,
                            duration: 300,
                            easing: 'ease-in-out',
                            opener: function() {
                                return $self.find('img');
                            }
                        }
                    });
                }
                if(ThemifyGallery.isVideo($link)){
                    $args['mainClass'] += ' video-frame';
                } else {
                    $args['mainClass'] += ' standard-frame';
                }
                if(ThemifyGallery.isInIframe()) {
                    window.parent.jQuery.magnificPopup.open($args);
                } else {
                    $.magnificPopup.open($args);
                    $(window).trigger('resize');
                }
            });

我确实添加了$(window).trigger('resize');,效果很好!我只需要在我自己的 scripts.js 中实现它,这样它就不会有一天被覆盖。

再次感谢,

迈克

Content not sizing to modal window until browser window resize

【问题讨论】:

    标签: jquery wordpress


    【解决方案1】:

    如果 window resize 事件可以解决您的问题,那么您可以在通过以下方式(在 jQuery 中)显示您的模态表单后简单地触发该事件:

     $(window).trigger('resize');
    

    进一步调试需要您的实际 HTML 标记和 JS 代码。

    【讨论】:

    • 感谢零分!页面link。模式由页面一半左右的“功能活动”按钮加载。根据我的研究,我将其缩小到您提供的相同触发器调整大小代码。我想我不知道在哪里以及如何称呼它。我的目标是什么 id/class?我可以将我的 scripts.js 中的代码与我的其他功能一起删除吗?很确定它正在使用 Magnific Popup。再次感谢!
    • @macmike78:我认为您在单击按钮或 JS 文件中的某些内容时会显示模态表单。我检查了链接,找到触发模态表单的点击事件需要时间。继续找到这段代码并将其添加到您的问题中。但这就是它在大多数情况下的工作方式,例如 Bootstrap 模态表单。当模态表单已经显示时,您会找到该单击事件并在事件末尾添加这一行代码。
    • 快到了!我找到了点击事件。可能是我需要加入它(在我自己的 scripts.js 中覆盖它,因为这可能有一天会被覆盖)。你能从代码中看出我是否可以调用那个函数吗?如您所见,我确实将您的代码添加到了底部,并且可以正常工作。正如我所说,我不能把它留在那里。谢谢!
    • @macmike78:您能否将那部分代码粘贴到您的问题中?点击事件代码和您添加的行。
    • 我编辑了我的原始帖子以包含代码。经过大量的修补和研究,我最终以两种不同的方式工作...(function ($) { $.magnificPopup.instance.open = function (data) { $.magnificPopup.proto.open.call(this, data); $(window).trigger('resize'); }; })(jQuery);(function ($) { $(document).on('mfpOpen', function () { $(window).trigger('resize'); }) })(jQuery); 非常感谢您的帮助!你让我走上了正确的道路。非常感谢零分。
    猜你喜欢
    • 1970-01-01
    • 2015-04-20
    • 1970-01-01
    • 2023-04-07
    • 1970-01-01
    • 1970-01-01
    • 2012-02-23
    • 1970-01-01
    • 2012-05-20
    相关资源
    最近更新 更多