2009-06-13 75 views
2

我有一个动态打开和关闭的JQuery对话框。一切都工作正常,除非对话的位置在关闭然后重新打开后不记得。JQuery UI对话框可以记住它在打开和关闭之间的位置

尺寸保持不变但位置不对。

我已经尝试连接到'Open'事件,但似乎在我手动重新定位元素后,位置正在被JQuery UI重置。

是否可以保持对话框的大小?我当然认为它应该是。

+0

你能提供一些代码或示例链接吗? – bendewey 2009-06-13 03:10:19

+0

你的意思是http://jqueryui.com/demos/dialog/? – 2009-06-13 03:23:38

+0

是 - JQuery UI对话框。对不起,如果不明确。 – berko 2009-06-15 03:49:41

回答

8

您可以使用jQuery UI对话框“beforeclose”事件来存储位置和大小。您可以使用“选项”方法设置位置和大小。

以下是目前对我的作品:

$(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()); 
     } 
    }); 
}); 

$( '#对话')对话框( '公开')

1

您可以通过返回的“beforeclose”虚假和使用jquery隐藏对话框覆盖标准close方法修复:

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

,这重新打开:

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