2011-05-10 45 views
1

我有一個搜索和替換的對話框。目前我使用下面的方法來重新調整窗口的位置。我需要保持窗口靜止在屏幕上(無論用戶拖動窗口的位置)而不移動它,或將其重新設置回屏幕中間,這正是jQuery("#dialog-form").dialog("option","position","center");目前所做的。jQuery對話框,當前屏幕上的靜態位置

下面是從documentation of jQuery dialog的樣品。我想知道如何根據當前視口設置修改設置值以重新定位窗口。所以當它自動在頁面上滾動時,它將始終保持在當前視口的X和Y上。

//getter 
var position = $(".selector").dialog("option", "position"); 
//setter 
$(".selector").dialog("option", "position", 'top'); 

回答

0

這是我的滾動做和調整:

$(window) 
     .resize(function() { 
      $('body').css('height', $(this).height()) 
      $('#alertsWindow').dialog("option", "position", ['left','bottom']); 
     }) 
     .scroll(function(){$(this).resize()}); 

它使對話框中的角落。 (你可以使用任何位置要使用)

從一jQuery UI page on dialogs

position String, Array      Default:'center' 
Specifies where the dialog should be displayed. Possible values: 
1) a single string representing position within viewport: 'center', 'left', 'right', 'top', 'bottom'. 
2) an array containing an x,y coordinate pair in pixel offset from left, top corner of viewport (e.g. [350,100]) 
3) an array containing x,y position string values (e.g. ['right','top'] for top right corner). 
+0

是否有可能填補'left'和'bottom'實際X和Y座標? – Webnet 2011-05-10 17:16:10

+0

@Webnet,是的。用你想要的任何座標填充它:-) – Neal 2011-05-10 17:21:01

+0

@Webnet,請參閱更新 – Neal 2011-05-10 17:25:52

0

你可以試試這個:

$(window).resize(function() {$(".selector").dialog("option", "position", ['center','top']);}); 

$(window).scroll(function() {$(".selector").dialog("option", "position", ['center','top']);}); 
0

我知道這個問題是舊的,但更好的修復是設置位置:固定在包含對話框元素上。沒有涉及的代碼,CSS將爲您處理所有事情。由於插件會合並CSS位置並將其設置爲絕對位置,因此在通過jQuery可調整大小的插件調整大小操作後,您需要將位置重置爲固定位置。