【问题标题】:Making a JQuery Dialog pop up box responsive使 JQuery 对话框弹出框响应
【发布时间】:2013-07-12 18:15:00
【问题描述】:

我的学校组织目前有一个包含 JQuery 并使用“对话框”弹出框(JQuery-UI?)的网站。我正在使网站具有响应性,但不知道如何使对话框具有响应性。我找到的唯一解决方案是 JQuery mobile,但我不确定如何将它实施到我们当前的网站中。我知道我的问题有点含糊,但我想知道是否有人有简单的解决方案?

这是我认为我的一个弹出框的代码。 (我不太了解代码)任何和所有的帮助都非常感谢。

$( "#dialog-new" ).dialog({
        resizable: false,
        width:900,
        modal: true,
        autoOpen: false,
        buttons: {
            "Clear Form": function() {
      clearForm($("#newapsform"));

    },
            "Create Request": function() {

                if(formIsOkay($("#newapsform")))
                {
                    $.ajax
                    ({  
                      type: "POST",  
                      url: "system/aps2.newrequest.php",  
                      data: $("#newapsform").serialize(),  
                      success: function() 
                        {  
                            $( "#dialog-new" ).dialog( "close" );
                            $("#goodmsg").html("Created photo request successfully!");
                            $('#goodmsgdiv').fadeIn(1500).delay(3000).fadeOut(1500);

                            datatables.fnDraw();
                            searchtables.fnDraw();
                            phototables.fnDraw();
                            clearForm($("#newapsform"));
                        },
          error: function() 
                        {  
                            $( "#dialog-new" ).dialog( "close" );
                            $("#badmsg").html("Could not create request: Use the force next time.");
                            $('#badmsgdiv').fadeIn(1500).delay(3000).fadeOut(1500);
                        }

                    });
                }
            }
        }
    }); 

【问题讨论】:

  • 一般来说,我认为您不应该让对话框具有响应性。对话框应该小而简洁。因此,它们无论如何都应该适合任何屏幕!如果它们很大,请重新考虑您的设计。
  • 我不知道这方面的最佳做法是什么,但恕我直言,应该为较小的屏幕实现对话框。我觉得处理手机上的对话并不容易。
  • 这不是我的网站。一位前员工设计了它,当时它仅用于台式机。现在我的经理希望可以从移动设备访问它。所以我必须让它响应。如果我有能力/时间重新设计整个东西,相信我会的。

标签: jquery jquery-ui mobile responsive-design


【解决方案1】:

我尝试了这个答案中的演示,当我调整我的笔记本电脑浏览器大小时它工作了。不过还没有在手机上试过。

Responsive jQuery UI Dialog ( and a fix for maxWidth bug )

这里的演示:http://codepen.io/jasonday/pen/amlqz

编辑:
看起来它适用于:
jquery-1.10.1.js
jquery-ui-1.9.2.js

$( "#dialog-new" ).dialog({
      autoOpen: true,
        width: 'auto', // overcomes width:'auto' and maxWidth bug
        height: 300,
        maxWidth: 600,
        modal: true,
        fluid: true, //new option
        resizable: false,
        open: function(event, ui){ 
           fluidDialog(); // needed when autoOpen is set to true in this codepen
        },

        buttons: {
            "Clear Form": function() {
      ....
});

// run function on all dialog opens
$(document).on("dialogopen", ".ui-dialog", function (event, ui) {
    fluidDialog();
});

// remove window resize namespace
$(document).on("dialogclose", ".ui-dialog", function (event, ui) {
    $(window).off("resize.responsive");
});

function fluidDialog() {
    var $visible = $(".ui-dialog:visible");
    // each open dialog
    $visible.each(function () {
        var $this = $(this);
        var dialog = $this.find(".ui-dialog-content").data("dialog");
        // if fluid option == true
        if (dialog.options.maxWidth && dialog.options.width) {
            // fix maxWidth bug
            $this.css("max-width", dialog.options.maxWidth);
            //reposition dialog
            dialog.option("position", dialog.options.position);
        }

        if (dialog.options.fluid) {
            // namespace window resize
            $(window).on("resize.responsive", function () {
                var wWidth = $(window).width();
                // check window width against dialog width
                if (wWidth < dialog.options.maxWidth + 50) {
                    // keep dialog from filling entire screen
                    $this.css("width", "90%");

                }
              //reposition dialog
              dialog.option("position", dialog.options.position);
            });
        }

    });
}

【讨论】:

  • 您能否将如何将其实现到我当前的代码中。我不是一个非常强大的编码器。 :(
猜你喜欢
  • 2012-06-07
  • 2012-02-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-11
  • 1970-01-01
相关资源
最近更新 更多