在页面上移动 Bootstrap 模态

Posted

技术标签:

【中文标题】在页面上移动 Bootstrap 模态【英文标题】:Moving Bootstrap modal on page 【发布时间】:2018-05-21 11:18:43 【问题描述】:

我在屏幕上有一个引导模式。当模态显示时,它位于屏幕的中心。

<div class="modal fade" id="ua_dialog">
<div class="modal-dialog">
    <div class="modal-content">
        <div class="modal-header">
        <div class="modal-body">
        ....
        </div>
      </div>

我需要在我的屏幕上移动模式,因为覆盖了我屏幕上的一些信息。用户应该能够向右移动,向左移动......等等。我可以这样做吗?我可以使用一些设置吗?还是用js?什么是最好的方法?谢谢!

【问题讨论】:

how to change the default positioning of modal in bootstrap?的可能重复 “我需要在我的屏幕上移动模态,因为覆盖了我的屏幕上的一些信息。” - 如果你有仍然需要访问的模态之外的信息,这可能宁愿表明首先在这里使用模态是错误的...... 它覆盖了需要可见的地图。我可以使模态可移动吗?或者我需要将模式定位在例如屏幕右侧? “我能把模态做成可移动的吗?” - 你能开始做你自己的基础研究吗……? ***.com/q/12591597/1427878 【参考方案1】:

我认为你需要这个:)

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

【讨论】:

【参考方案2】:

.modal-content
    margin-top:50px !important;

【讨论】:

在你的 CSS 中使用 !important

以上是关于在页面上移动 Bootstrap 模态的主要内容,如果未能解决你的问题,请参考以下文章

Bootstrap 3 模态触发并导致页面暂时向左移动/浏览器滚动条问题

bootstrap 模态框 modal 插件在一个含有多个页面

简单的bootstrap模态框问题

移动设备上的 Twitter Bootstrap 模式

Bootstrap 模态对话框选项卡在后面的页面中

懂bootstrap的过来看看,bootstrap模态框的问题