javascript - 特定角度 5 组件之上的 Jquery/bootstrap 模式
问题描述
我bootstrap
在我的 Angular 5 项目中使用模态来打开模态。但是我现在这样做的方式是让模态在整个屏幕上打开,这是我不希望发生的。
这是我的角度布局代码。
<div class="wrapper">
<div class="sidebar" data-active-color="white" data-background-color="black" data-image="../assets/img/sidebar-1.jpg">
<!-- <div class="sidebar" data-color="red" data-image=""> -->
<sidebar-cmp></sidebar-cmp>
<div class="sidebar-background" style="background-image: url(assets/img/sidebar-1.jpg)"></div>
</div>
<div class="main-panel">
<navbar-cmp></navbar-cmp>
<router-outlet></router-outlet>
<div *ngIf="!isMap()">
<footer-cmp></footer-cmp>
</div>
</div>
</div>
如您所见,有sidebar
组件和router-outlet
,模态存在于router-outlet
组件中,但仍显示在sidebar
组件顶部。两个组件并排显示。
这就是我在打字稿文件中显示模式的方式:
@ViewChild('DetailModal') detailRef: ElementRef;
$(this.detailRef.nativeElement);
$(this.detailRef.nativeElement).modal("show");
模态内容在组件的定义中:
<div>
<!-- The definition of the Component that gets in the router-outlet-->
<div class=" container modal fade" #DetailModal>
<app-detail-modal [Cert]="DCert"></app-detail-modal>
</div>
</div>
如何使模态仅显示在它所在的组件之上?
解决方案
您可以通过使您的容器位置相对和模态容器位置绝对来使用 css 将实际模态定位在容器内
#my-modal-container {
height:300px;
width: 600px;
border: 4px solid green;
position: relative;
}
.modal {
position: absolute;
}
然后,您可以隐藏引导覆盖并将其替换为内联覆盖。
// Hide the default backdrop
.modal-backdrop {
display: none;
}
// Make another backdrop with styles copied from the jQuery one, and
// place it alongside your modal component
body.modal-open .inline-modal-backdrop {
position: absolute;
opacity: 0.5;
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: 1040;
background-color: #000;
}
然后您可以将所有这些包装在一个包含 bs 模态容器和新的内联背景的角度组件中
<div class="modal"><ng-content></ng-content></div>
<div class="inline-modal-backdrop"></div>
这是一个codepen(没有角度)
推荐阅读
- javascript - JSON对象名称未定义,如何访问参数?
- react-native - react-native-fast-image 是否会缓存在 src 中使用 require 加载的图像
- shopware - 商店软件登录不起作用,那么实际问题是什么?
- javascript - 画布 - 在 Firefox 中剪辑图像并使用复合操作“乘法”不像在 Chrome 中那样工作
- ios - 如何为其他开发者提供 App 名称?
- javascript - 基于键及其值的 GroupBy 数组
- python - 使用 matplotlib 绘制分类数据 - 转置 pandas 数据框
- docker - 如何与 kubernetes 集群共享我的谷歌云实例的卷
- android - APK 在 main.py 问题中使用 txt 文件
- javascript - JavaScript 从一个值执行 Object.entries()