javascript - 在居中元素上使用 Angular CDK DragDropModule
问题描述
我正在尝试DragDropModule
在居中组件上使用 Angular CDK。这工作正常,但是在拖动操作开始时,居中的组件移动到右上角,因为我用来使组件居中的转换被 CDK 拖动转换覆盖。
居中的组件显示在全屏覆盖的顶部,因此我不能使用 flexbox 布局(至少据我所知)。在现实生活中,居中的组件是一个模态对话框......
这是我的 MVCE 组件:
import { Component, OnInit } from "@angular/core";
@Component({
selector: "app-centered-panel",
styles: [
`
div.centered {
background-color: red;
width: 200px;
height: 200px;
}
`,
`
.overlay {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
background-color: rgba(0, 0, 0, 0.5);
}
`,
`
.centered {
position: absolute;
left: 50%;
bottom: 50%;
transform: translateX(-50%) translateY(50%);
}
`
],
template: `
<div class="overlay"></div>
<div class="centered" cdkDrag></div>
`
})
export class CenteredPanelComponent implements OnInit {
constructor() {}
ngOnInit() {}
}
有没有办法让阻力知道当前的转变?或者有没有更好的方法将页面上的可拖动 div 与叠加层一起居中?
这个 stackblitz 展示了问题的实际效果:
解决方案
推荐阅读
- javascript - 获取隐藏输入Vue.Js的自动完成输入值
- android - 泄漏的窗口,但希望在用户单击肯定按钮时完成活动
- f# - 如何为 Saturn 应用程序构建集成测试
- javascript - 试图从 API 中列出用户的最爱,得到“TypeError: null is not an object (evalating 'firebase.auth().currentUser.uid')
- node.js - 我在 Heroku 上的 Node.js 应用程序没有显示在浏览器 Android 手机中
- python - 如何在 Opencv 图像上剪切选区
- android - 错误:功能必须是有效的 BrowserStack App-Automate App URL
- javascript - 使用事件侦听器检测按钮的点击,然后增加 html 元素的计数
- java - JPA如何从ManyToMany关系中的对象的Arraylist中获取属性
- c# - 如何在 EmguCV 中保存具有透明背景的图像