2010-07-27 29 views
4

有沒有一個讓jQuery對話框在任何時候都可拖動的技巧? (我的意思不只是在標題欄中)jQuery對話框:在任何點拖動對話框

+0

好問題,但我喜歡它的工作原理是這樣的事實其他窗口,可以通過標題欄拖動。 – 2010-07-27 14:40:34

回答

2

與可排序項目相反,對話項目沒有該功能(我不知道爲什麼)。如果需要的話,你也許能夠做這樣的事情:

$(document).ready(function() { 
    var 
     // Create dialog 
     dialog = $('div') 
      .dialog({ title: "I'm a dialog" }) 
      .css({cursor: 'move'}), 

     // Get the options manually 
     options = dialog 
      .data("dialog") 
       .uiDialog 
       .data('draggable') 
        .options; 

    // Finally, extend the draggable modal box's 
    // options and remove any restrictions 
    $.extend(options, {cancel: '', handle: ''}); 
}); 

看到這裏工作的例子:http://jsfiddle.net/gMP2d/

+0

不錯,謝謝 – albanx 2010-07-28 07:08:07

0
$("#div_id") 
    .dialog({ 
     position: [3,442], 
     width: 300, 
     height: 90 
    }) 
    .css({cursor: 'move'}) 
    .parent() 
    .draggable({cancel:'',handle:''}); 
+0

爲什麼你要取得$('#div_id')的父容器,而不是隻讓$('#div_id')可拖動? – 2012-10-02 13:28:45