【问题标题】:SimpleModal resizing the containerSimpleModal 调整容器大小
【发布时间】:2008-12-29 13:03:19
【问题描述】:

我用过SimpleModal。现在的问题是模式对话框的大小调整。 我有一个确认对话框,按Yes后基本上很小。

第二个是my.php,它包含大量数据。我正在使用的概念 附加一个已经存在的模型。如何调整内容的大小?

我的 JavaScript sn-p 有:

$(document).ready(function () {
    $('#confirmbutton, #confirmDialog a.confirm').click(function (e) {
        e.preventDefault();

        confirm("Continue to the SimpleModal project page?", function () {
        window.location.href = 'http://localdata/';
        });
    });
});

function confirm(message, callback) {
    $('#confirm').modal({
        close:false,
        position: ["20%",],
        overlayId:'confirmModalOverlay',
        containerId:'confirmModalContainer',
        onShow: function (dialog) {
            dialog.data.find('.message').append(message);

            // If the user clicks "yes"
            dialog.data.find('.yes').click(function () {
                // Call the callback
                // $.modal.close();

                $.get("my.php", function (data) {
                    /* Sample response:
                     *   <div id="title">My title</div>
                     *   <div id="message">My message</div>
                     *
                    */

                    var resp = $("<div/>").append(data);
                    var title = resp.find("#title").html(),
                    message = resp.find("#message").html();
                    dialog.data.find(".header span").html(title);
                    dialog.data.find(".message").html(message);
                    dialog.data.find(".buttons .yes").hide();
                    dialog.data.find(".buttons .no").hide();

                    //dialog.data.find(".buttons .no").html("Close");

                    // No need to call the callback or $.modal.close()
                });// End for click
            });//End for on show
        } //End for modal
    }); //Close for modal
}

我的 CSS:

confirmModalContainer {height:700px; width:700px; font-family:'Trebuchet MS', Verdana, Arial; font-size:16px; text-align:left; background:#fff; border:2px solid #336699;}

如何修改 SimpleModal 容器大小?在 Ajax 调用中?

【问题讨论】:

    标签: jquery ajax model resize


    【解决方案1】:

    就这样吧....

    $("#simplemodal-container").css('height', 'auto'); //To reset the container.
    $(window).trigger('resize.simplemodal');           //To refresh the modal dialog.
    

    【讨论】:

    • 哇,我正在寻找解决同样的问题,这个解决方案很棒!为了双向调整大小,我还添加了(在触发之前): $("#simplemodal-container").css('width', 'auto');
    【解决方案2】:

    我想提出一个更简单、更灵活的解决方案:

    访问http://www.ericmmartin.com/simplemodal-test/,在Firebug中运行以下代码,然后点击对话框中的“按钮”来调整它的大小。

    // Inject a CSS class into the document
    $('head style[type=text/css]').append('.wide{width:750px !important;}');
    
    $('#modalContentTest').modal({
      onShow:function(dialog){
        dialog.data.find('.animate').click(function(){
    
          // You can put this code in your "my.php" callback
    
          dialog.container.addClass('wide');
    
          /*
          // OR set the width explicitly
          // (make sure you remove the addClass line if you want to use this)
          dialog.container.width(700);
          */
    
          /*
            Force SimpleModal to reposition the 
            dialog by triggering its resize event
          */
          $(window).trigger('resize.simplemodal');
    
        }); //end click
      } // end onShow
    }); // end modal
    

    使用这种方法,您不必定义新的 CSS 来重新居中对话框,并且可以让 SimpleModal 处理浏览器的不一致问题。

    【讨论】:

      【解决方案3】:

      您可以通过添加和删除 modalContainer 元素的类来实现。

      Fog Creek Copilot 使用 SimpleModal,有两种尺寸,普通和宽。如果您转到 Copilot 并单击“登录”,您将看到正常大小。现在,放入 Firebug 的控制台

      >> $('.modalContainer').addClass('wide')
      

      您应该看到容器变宽了。要在您的网站上进行这项工作,您所要做的就是为您想要的所有尺寸定义类,并动态添加和删除它们。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-12-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-04-29
        • 2017-06-06
        • 2012-11-11
        相关资源
        最近更新 更多