2014年2月15日 星期六

[Javascript] 將Bootstrap中的Modal設定成可拖曳及變換位置

以Bootstrap官網例子,並加上modal-dialog的id "myModalDialog",因為主要需要跟改的部份都在modal-dialog

<!-- Button trigger modal -->
<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
  Launch demo modal
</button>

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog" id="myModalDialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="myModalLabel">Modal title</h4>
      </div>
      <div class="modal-body">
        ...
      </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>
  </div>
</div>
設定成可拖曳:利用jqueryui

$('#myModalDialog').draggable();

變換位置:變更modal-dialog的css

$('#myModalDialog').css("position", "absolute");
$('#myModalDialog').css("left", "100px");
$('#myModalDialog').css("top", "100px");

關鍵字
Bootstrap
Modal
draggable
position


沒有留言: