ngx-bootstrap将子模态置于模态上方

埃沃马克

我有一个使用ngx-bootstrap v5.6.1的Angular 8应用程序,该应用程序打开一个模式,然后在某些情况下,在第一个模式之上打开第二个模式。两者都可以正常工作,但是第二个模式位于屏幕的中心,而不是屏幕下方的模式。这很可能是因为我正在将类:“ modal-md modal-dialog-centered”传递给第二个模态,但是除了将“ centered”移到第二个模态之外,我一直无法找到一种方法来重新定位第二个模态。让它出现在顶部。

我想将第二个模式移动到屏幕上,也许再增加10%-20%。这两个模态都是它们自己独立的组件,因为我想使第二个模态在整个应用程序中可重用。

这就是我所说的模态

第一种模式:

this.bsModalRef = this.modalService.show(ModalComponent, { class: 'modal-lg', backdrop: 'static' });

第二模态:

this.bsModalRefConf = this.modalService.show(ConfirmModalComponent, { class: 'modal-md modal-dialog-centered', backdrop: 'static' });

这些都使用ngx-bootstrap / modal中的BsModalService

谢谢!

同样适用.modal-dialog-centered于大型模态,并向上移动较小的模态,使其.modal-content底边距。它必须是大小的两倍,因为它是使用flexbox居中的。因此,要将其向上移动15vh(占设备屏幕高度的15%),您需要将底部边距设置为30vh

看到它正常工作(在扩展模式下):

#exampleModalCenter2 .modal-content {
  margin-bottom: 30vh;
}
.modal-content {
  box-shadow: 0 5px 6px -3px rgba(0,0,0,.2), 0 9px 12px 1px rgba(0,0,0,.14), 0 3px 16px 2px rgba(0,0,0,.12);
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>

<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModalCenter">
  Launch first modal
</button>

<div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  <div class="modal-dialog modal-dialog-centered modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLongTitle">Modal title</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        ...
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary"  data-toggle="modal" data-target="#exampleModalCenter2">Open second modal</button>
      </div>
    </div>
  </div>
</div>
<div class="modal fade" id="exampleModalCenter2" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  <div class="modal-dialog modal-dialog-centered modal-md" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLongTitle">Modal title</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        ...
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>

由于只能使用骇人的DOM操作在其他模态之上渲染背景,因此我使用进行了视觉上的分离box-shadow

更好的方法是在打开较小的模态时更改较大模态的不透明度,并将其z-index降低1您可以使用以下方法实现此目的:

  1. javascript:根据小类是否打开,动态地向大类添加一个类,并更改其类别opacity以及z-index何时应用该类。
  2. css:要在没有js的情况下执行此操作,您要做的就是将DOM中的大一个放在小一个之后,作为同级,然后使用~组合器。演示:

#exampleModalCenter2 .modal-content {
  margin-bottom: 20vh;
}
.modal-content {
  box-shadow: 0 5px 6px -3px rgba(0,0,0,.2), 0 9px 12px 1px rgba(0,0,0,.14), 0 3px 16px 2px rgba(0,0,0,.12);
}
.modal.show {
  opacity: 1;
  transition: opacity .3s ease-in-out;
}
.modal.show ~ .modal.show,
.modal.show ~ .modal.show * {
  opacity: .5;
  pointer-events: none;
  z-index: 1049;
}
.modal-backdrop.show ~ .modal-backdrop.show {
  opacity: 0;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>

<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModalCenter">
  Launch first modal
</button>

<div class="modal fade" id="exampleModalCenter2" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  <div class="modal-dialog modal-dialog-centered modal-md" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLongTitle">Modal title</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        ...
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>
<div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  <div class="modal-dialog modal-dialog-centered modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLongTitle">Modal title</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        ...
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary"  data-toggle="modal" data-target="#exampleModalCenter2">Open second modal</button>
      </div>
    </div>
  </div>
</div>

...在这一点上,将小个子向上移动变得不那么重要了。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Angular ngx-bootstrap-如何制作大而宽的模态

来自分类Dev

带有 ngx-bootstrap 的模态给我错误:无法读取未定义的属性“显示”

来自分类Dev

禁用ngx-bootstrap popover?

来自分类Dev

是否有ngx-bootstrap'card'组件?

来自分类Dev

ngx-bootstrap:可按模板排序(水平)

来自分类Dev

ngx-bootstrap datepicker验证无效日期

来自分类Dev

ngx-bootstrap轮换的响应式变化

来自分类Dev

Angular ngx-bootstrap隐藏标签内容

来自分类Dev

构建 ngx-bootstrap 时出错

来自分类Dev

ngx-bootstrap modal 单例问题

来自分类Dev

如何通过单击angular7中的模态组件外部来隐藏ngx-simple-modal?

来自分类Dev

如何在 ngx-modal 中以编程方式关闭模态对话框

来自分类Dev

离子模态打开以前的模态

来自分类Dev

找不到模块:错误:无法解析“ ngx-bootstrap”

来自分类Dev

ngx-bootstrap datepicker输出格式不是ISO格式

来自分类Dev

如何在ngx-bootstrap-modal中添加模糊效果

来自分类Dev

下拉模块在 ngx-bootstrap 中不可用

来自分类Dev

如何为 ngx-bootstrap typeahead 添加向上/向下滚动?

来自分类Dev

在 Angular 应用中使用 Kendo UI 和 NGX Bootstrap

来自分类Dev

将 ngx-admin 从 2.3.0 更新到 3.0.0

来自分类Dev

将ng-repeat值传递到离子模态

来自分类Dev

离子模态底部间距

来自分类Dev

离子模态不显示

来自分类Dev

使用ngx-bootstrap modal将数据传递给modal

来自分类Dev

使用Bootstrap 3将标签置于输入上方

来自分类Dev

关闭WPF模态窗口后如何将MFC对话框置于前台

来自分类Dev

从Bootstrap模态窗口中删除模态属性

来自分类Dev

Bootstrap 3模态背景落在模态前面

来自分类Dev

twitter bootstrap 3模态为非模态

Related 相关文章

热门标签

归档