2014-11-25 64 views
6

我試圖使用jquery-ui可拖動功能引導模式彈出。 我用這樣的:jquery拖動引導模態,滾動奇怪的行爲

 // Bootstrap modal 
     $(element).modal({ keyboard: false, 
          show: value 
     }); 
     // Jquery draggable 
     $(element).draggable({ 
      handle: ".modal-header" 
     }); 

但是,當我嘗試拖動彈出右側滾動與彈出拖動。 Thx任何提前。

+1

讓你的問題的小提琴 – Innodel 2014-11-25 07:22:03

回答

32

我想你應該在.modal-dialog類應用draggable,請參見:

<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet"/> 
 
<script src="//code.jquery.com/jquery-1.10.2.js"></script> 
 
<script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script> 
 

 
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script> 
 
<div> 
 
<div class="modal fade"> 
 
    <div class="modal-dialog"> 
 
    <div class="modal-content"> 
 
     <div class="modal-header"> 
 
     <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button> 
 
     <h4 class="modal-title">Modal title</h4> 
 
     </div> 
 
     <div class="modal-body"> 
 
     <p>One fine body&hellip;</p> 
 
     </div> 
 
     <div class="modal-footer"> 
 
     <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> 
 
     <button type="button" class="btn btn-primary">Save changes</button> 
 
     </div> 
 
    </div><!-- /.modal-content --> 
 
    </div><!-- /.modal-dialog --> 
 
</div><!-- /.modal --> 
 
</div> 
 

 
<script> 
 
     $('.modal').modal({ keyboard: false, 
 
          show: true 
 
     }); 
 
     // Jquery draggable 
 
     $('.modal-dialog').draggable({ 
 
      handle: ".modal-header" 
 
     }); 
 
</script>

+0

謝謝!你是對的。我的錯。我不明白我以前怎麼不明白。 :) – Maris 2014-11-26 06:11:59

+0

非常感謝。這個解決方案完美運作 – luongnv89 2014-12-23 11:28:31

+0

它完美的作品。謝謝! – 2015-10-29 14:00:58

0

通過@Bass Jobsen

尼斯回答不過我覺得有時候我們可能需要動態調整模式。所以在這裏擴展低音的解決方案,調整大小,拖動模式

加成

<link rel="stylesheet" href="https://code.jquery.com/ui/1.11.3/themes/smoothness/jquery-ui.css" /> 

$('.modal-content').resizable();

<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet"/> 
 
<link rel="stylesheet" href="https://code.jquery.com/ui/1.11.3/themes/smoothness/jquery-ui.css" /> 
 
<script src="//code.jquery.com/jquery-1.10.2.js"></script> 
 
<script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script> 
 

 
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script> 
 
<div> 
 
<div class="modal fade"> 
 
    <div class="modal-dialog"> 
 
    <div class="modal-content"> 
 
     <div class="modal-header"> 
 
     <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button> 
 
     <h4 class="modal-title">Modal title</h4> 
 
     </div> 
 
     <div class="modal-body"> 
 
     <p>One fine body&hellip;</p> 
 
     </div> 
 
     <div class="modal-footer"> 
 
     <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> 
 
     <button type="button" class="btn btn-primary">Save changes</button> 
 
     </div> 
 
    </div><!-- /.modal-content --> 
 
    </div><!-- /.modal-dialog --> 
 
</div><!-- /.modal --> 
 
</div> 
 

 
<script> 
 
     $('.modal').modal({ keyboard: false, 
 
          show: true 
 
     }); 
 
     // Jquery draggable 
 
     $('.modal-dialog').draggable({ 
 
      handle: ".modal-header" 
 
     }); 
 
     $('.modal-content').resizable(); 
 

 
</script>

此外,你可以指定了minHeight和M inWidth

$('.modal-content').resizable({ 
    minHeight: 100, 
    minWidth: 100 
});