angular - 元素上方的角度材质覆盖
问题描述
我正在尝试在目标元素下方附加一个叠加层并且它可以工作,但似乎我无法将它附加到目标元素的顶部。
<button (mouseenter)="openFusilliPanel()" (mouseleave)="closeFusilliPanel()">
Hover to append
</button>
<!-- I would like to append it above this DIV element -->
<div cdkOverlayOrigin #tortelliniOrigin="cdkOverlayOrigin" #appendDiv style="background:pink;width:400px;height:100px;color:black;margin-top:100px;">Should append overlay on top of this element</div>
<!-- Template to load into an overlay. -->
<ng-template cdk-portal>
<p style="background-color: mediumpurple;width:100px;" class="demo-fusilli"> Fusilli </p>
</ng-template>
来源
const positionStrategy = this.overlay.position().connectedTo(
this.tortelliniOrigin.elementRef,
{ originX: 'start', originY: 'bottom' },
{ overlayX: 'start', overlayY: 'top' })
.withFallbackPosition(
{ originX: 'start', originY: 'top' },
{ overlayX: 'start', overlayY: 'bottom' })
.withFallbackPosition(
{ originX: 'end', originY: 'top' },
{ overlayX: 'start', overlayY: 'top' })
.withFallbackPosition(
{ originX: 'start', originY: 'top' },
{ overlayX: 'end', overlayY: 'top' })
.withFallbackPosition(
{ originX: 'end', originY: 'center' },
{ overlayX: 'start', overlayY: 'center' })
.withFallbackPosition(
{ originX: 'start', originY: 'center' },
{ overlayX: 'end', overlayY: 'center' })
;
this.fusilliOverlayRef = this.overlay.create({ positionStrategy });
this.fusilliOverlayRef.attach(this.templatePortals.first);
演示链接:https ://stackblitz.com/edit/overlay-demo-2nssno
我在想我正在使用connectedTo()
它创建相对于附加元素的覆盖,我们如何将它设置为显示relative
在附加元素上方而不是底部?
有谁知道如何在目标元素(粉红色)的(红色框)上方附加叠加层(紫色)?
解决方案
行。我发现这行得通。
{ originX: 'start', originY: 'top' },
{ overlayX: 'start', overlayY: 'bottom' })
推荐阅读
- java - auto.register.schemas 是否应该在修改 .avsc 时在模式注册表中创建一个新版本?
- android - Android Studio 错误地保存密码--添加了额外的字符
- python - 如何从地图中一次检索 2 个值 - 在 Python 3.x 中
- java - 如何使用 android studio 中的 MediaStore Api 在 android 11 中获取特定文件夹,如 WhatsApp (.Status) 文件夹
- elasticsearch - 过滤器不适用于弹性搜索中嵌套字段的非嵌套聚合
- python - Neo4J python驱动程序在运行到docker容器时不会引发错误
- woocommerce - 获取产品变体描述以显示在 woocommerce 中的订单项目上?
- tomcat - Jersey jax-rs 应用程序在使用 Tomcat 9 的端点上返回 404 错误
- robotframework - Robotframework 获得重复迭代
- css - 如何在自定义 CSS 类中使用 tailwindcss 颜色?