简体   繁体   English

更改模式对话框以加载接近页面顶部

[英]Change modal dialog to load close to top of the page

I have a jQuery modal dialog that is loading perfectly fine but my issue is that I am using little old version of jQuery(1.12.4) and I cannot upgrade it and I want to center the modal close to the top of the page like I have it in this Fiddle .我有一个 jQuery 模态对话框,加载非常好,但我的问题是我使用的是旧版本的 jQuery(1.12.4),我无法升级它,我想将模态框居中靠近页面顶部,就像我一样把它放在这个Fiddle里。 I am using the below code to make it work and position: ['center',20], is making it close to the top but again since I am using an old version of the jQuery it is not working for me.我正在使用下面的代码使其工作,并且 position: ['center',20] 使其接近顶部,但由于我使用的是旧版本的 jQuery 它对我不起作用。 Can someone suggest any other alternaate.有人可以建议任何其他替代品。

$('#open').click(function() {
    $('#dialog').dialog('open');

});

$(document).ready(function() {
    jQuery("#dialog").dialog({
        autoOpen:false,
        width:500,
        position: ['center',20],               
        modal: true,
        resizable: true,
        draggable: true,
        closeOnEscape: true,        
        title: "Alerts",       
        buttons: {
            OK: function () {
                $(this).dialog("close");
            }
        }
    });
});

In my case loading on the top left corner as shown below在我的情况下,加载在左上角,如下所示页

According to the documentation you need to change this line from:根据文档,您需要将此行更改为:

position: ['center',20], 

to:至:

position: { my: "center", at: "top", of: window },

Your updated fiddle here , the snippet:在这里更新的小提琴,片段:

 $('#open').click(function() { $('#dialog').dialog('open'); }); $(document).ready(function() { jQuery("#dialog").dialog({ autoOpen:false, width:500, position: { my: "center", at: "top", of: window }, modal: true, resizable: true, draggable: true, closeOnEscape: true, title: "Alerts", buttons: { OK: function () { $(this).dialog("close"); } } }); });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/start/jquery-ui.css"> <script src="https://code.jquery.com/ui/1.8.16/jquery-ui.min.js"></script> <div id="dialog">modal dialog</div> <a href="#" id="open">Open dialog</a>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM