2010-02-05 80 views
3

後,我有以下jQueryUI的對話框:jQueryUI的對話框定位垂直滾動

 $("#dialog").dialog({ 
     bgiframe: true, 
     autoOpen: false, 
     height: 420, 
     hide: 'slide', 
     modal: true, 
     buttons: { 
          'Annuler': function() { 
       $(this).dialog('close'); 
      }, 
      'Envoyer votre message': function() {} 
} 

當我與它顯示:

$('#question-annonceur').click(function() { 
     $('#dialog').dialog('open'); 
    }); 

這幾乎居中。但是當我垂直滾動時,它不再居中 事實上,對話框仍然居中(關於用戶設置的滾動條位置),但滾動條已滾動到窗口的頂部,然後,該對話框不再居中(因爲它是關於新的滾動條的位置爲中心)。

它的存在屬性我可以設置使滾動條不重置在這樣的頂部?

感謝。

回答

8

從位置更改CSS:絕對位置:固定對我有效:

.ui-dialog { position: fixed; padding: .1em; width: 300px; overflow: hidden; } 
2
jQuery(window).scroll(function() { 
    jQuery('#dialog').dialog('option','position','center'); }); 

作品我的jQuery 1.9

這是假設你的對話框有ID = 「對話框」

+1

非常漂亮:優雅簡潔。 – 2014-02-22 00:37:08

+0

將偵聽器附加到窗口對象上的滾動事件_without debouncing_正在尋求麻煩。 – vrutberg 2015-03-06 12:07:10