Bootstrap Jquery可拖动,带有引导模式,滚动条行为奇怪

slwdgvem  于 2022-12-16  发布在  Bootstrap
关注(0)|答案(2)|浏览(143)

我尝试使用引导模式弹出窗口和jquery-ui拖拽功能,我是这样使用的:

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

但当我试图拖动弹出右滚动条是拖动popup. Thx的任何进展。

vsdwdz23

vsdwdz231#

我认为您应该在.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>
70gysomp

70gysomp2#

@Bass Jobsen的回答不错
但是我觉得有时候我们可能需要动态地调整模态的大小,所以在这里扩展了Bass的解决方案,使模态可以调整大小和拖动
添加

<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和minWidth

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

相关问题