我一直在试图找到解决问题的解决方案:我有两个同级div标签。在第二个中,有一个按钮显示具有深色覆盖的模态对话框,但是,在我的示例中,第一个DIV坐在此模态对话框的顶部。我了解为什么(堆叠概念)的原因,但是我需要在不改变此结构的情况下创建一些工作解决方案。
模态对话框打开了布尔属性。有什么办法可以动态地聆听此属性的值,并在NGCLASS的帮助下,将第二个兄弟姐妹的Z索引更改为页面上最高的Z-索引,并在打开模式时,并删除此NGCLASS,只要模态无需屏幕上打开更长的时间?
非常感谢您的任何帮助或建议。
<div style='z-index: 2'></div>
<div style='z-index: 1'>
<button (click)="openModal()">Open modal</button>
<div id="modal" style='z-index: 3'>Here is the modal content</div>
</div>
I´ve been trying to find solution for the problem: I have two sibling div tags. In the second one, there is a button to display modal dialog with the dark overlay, however, in my example the first div is sitting on the top of this modal dialog. I understand the reason why (stacking concept) but I need to create some working solution without changing this structure.
The modal dialog has boolean attribute opened. Is there any way I can dynamically listen to this attribute´s value and with the help of ngClass change the z-index of the second sibling to the highest one on the page when the modal is opened and remove this ngClass whenever the modal is no longer opened on the screen?
Thank you very much for any help or suggestion.
<div style='z-index: 2'></div>
<div style='z-index: 1'>
<button (click)="openModal()">Open modal</button>
<div id="modal" style='z-index: 3'>Here is the modal content</div>
</div>
发布评论
评论(1)
If changing structure is an option, I would recommend @Drenai's approch in the
首先,正如您提到的,在控制器中维护布尔值变量,该变量说明模态是否打开。 (让我们命名
iSmodaloped
。)在您的样式表中,位置
div#modal
recient;延伸到屏幕的末端。div#modal
将用作模态内容的覆盖,而模态将用作实际模态框。在您的html中,将模态的内容包装在
.modal-content
div中,然后使用ismodalopened
才有条件地呈现模态。请注意,当单击“打开模态”按钮时,
iSmodaloped
将设置为true
,同时单击模态的关闭按钮集ismodalopened
<false
。这样,模态的打开和关闭功能应起作用,而在fileve
模态的位置
解决您的z索引问题时。If changing structure is an option, I would recommend @Drenai's approch in the comments. However, if changing structure is not an option, here's a solution involving CSS, with bits taken from W3Schools.
First, as you mentioned, maintain a boolean variable in your controller that states whether the modal is opened or not. (Let's name it
isModalOpened
.)In your stylesheet, position
div#modal
fixed; stretched to the ends of the screen.div#modal
will serve as the overlay of the modal content, while the modal will serve as the actual modal box.In your HTML, wrap the content of your modal within a
.modal-content
div, and useisModalOpened
to conditionally render the modal only when the modal's state is opened.Notice that when the "Open modal" button is clicked,
isModalOpened
is set totrue
, while clicking the modal's close button setsisModalOpened
tofalse
. This way, the modal's open and close functionality should work, all while your z-index issue is solved byfixed
ing the modal'sposition
.