Can JQuery UI Dialog remember its position between opening and closing

ⅰ亾dé卋堺 提交于 2019-12-24 01:58:21

问题


I have a JQuery dialog that I dynamically open and close. Everything is working fine except the position of the dialog is not remembered after it is closed and then reopened.

The size is maintained but the position is not.

I have tried hooking into the 'Open' event but it appears that the position is being reset by JQuery UI after I manually reposition the element.

Is maintaining the size of the dialog possible? I certainly think it should be.


回答1:


You could use the jQuery UI Dialog "beforeclose" event to store the position and size. You can set both position and size using the "option" method.

Here is what currently works for me:

$(function() {
    $("#dialog").dialog({
        beforeclose: function(){
            $(this).dialog('option', 'position', [$(this).offset().left, $(this).offset().top]);
            $(this).dialog('option', 'width', $(this).width());
            $(this).dialog('option', 'height', $(this).height());
        }
    });
});

$('#dialog').dialog('open')




回答2:


You can override the standard close method by returning false on 'beforeclose' and using jquery to hide the dialog:

$.ui.dialog.defaults.beforeclose = function() {
    $(this).closest('.ui-dialog').hide();
    return false;
};

and this to reopen:

$('#list').closest('.ui-dialog').show();



回答3:


Take a look at jquery changeset. You'll also find a fix for this



来源:https://stackoverflow.com/questions/989759/can-jquery-ui-dialog-remember-its-position-between-opening-and-closing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!