简体   繁体   English

角度4 | 转换不适用于条件CSS类

[英]Angular 4 | Transitions don't work with conditional css classes

I've been searching stackoverflow for a while now and I don't think this has been answered yet. 我一直在搜索stackoverflow已有一段时间了,但我认为这还没有得到解决。 I Have a conditional class on a div that gets added to the div when a boolean variable is set to true. 我在div上有一个条件类,当将布尔变量设置为true时,该条件类会添加到div中。 Following code: 以下代码:

<div [class.modalwindow-show]="modalState" class="modals">

    [...]

</div>

When the user clicks a button the variable is set to true and the class modalwindow-show gets added to the div. 当用户单击按钮时,变量将设置为true,并且将modalwindow-show类添加到div中。 My problem is that out of some reason the css transition is not working, the background just changes without a transition. 我的问题是,出于某些原因,css过渡无法正常工作,背景只是在没有过渡的情况下发生了变化。 I have these two classes: 我有这两节课:

.modals{
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    transition: all .30s ease-in-out;
}

.modalwindow-show{
    background: rgba(10,10,10,0.5);
    display: block;
}

Does anyone know why the transition is not working? 有谁知道为什么过渡不起作用?

Fixed! 固定!

I entirely removed display: none and display: block and am now using visibility: hidden and visibility: visible. 我完全删除了display:none和display:block,现在正在使用可视性:隐藏和可视性:可见。 display was overriding the transition. 显示覆盖了过渡。

.modals{
    visibility: hidden;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    transition: all .30s ease-in-out;
}

.modalwindow-show{
    visibility: visible;
    background: rgba(10,10,10,0.5);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM