Javascript 过渡CSS3在Angular2中不工作?
我正在尝试添加全屏导航区域,我已经做到了,但是转换不起作用,但是另一个CSS代码起作用了,我错过了什么?在使用angular2时,我是否需要添加一些内容 这是我的组件文件夹,看起来像: 下面是我的css文件navbar.component.css:Javascript 过渡CSS3在Angular2中不工作?,javascript,html,css,angular,Javascript,Html,Css,Angular,我正在尝试添加全屏导航区域,我已经做到了,但是转换不起作用,但是另一个CSS代码起作用了,我错过了什么?在使用angular2时,我是否需要添加一些内容 这是我的组件文件夹,看起来像: 下面是我的css文件navbar.component.css: body { margin: 0; font-family: 'Lato', sans-serif; } .overlay { height: 100%; width: 100%; position: fi
body {
margin: 0;
font-family: 'Lato', sans-serif;
}
.overlay {
height: 100%;
width: 100%;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: rgb(0,0,0);
background-color: rgba(0,0,0, 0.9);
overflow-x: hidden;
transition: 0.5s;
}
.overlay-content {
position: relative;
top: 25%;
width: 100%;
text-align: center;
margin-top: 30px;
}
.overlay a {
padding: 8px;
text-decoration: none;
font-size: 36px;
color: #818181;
display: block;
transition: 0.3s;
}
.overlay a:hover, .overlay a:focus {
color: #f1f1f1;
}
.overlay .closebtn {
position: absolute;
top: 20px;
right: 45px;
font-size: 60px;
}
@media screen and (max-height: 450px) {
.overlay a {font-size: 20px}
.overlay .closebtn {
font-size: 40px;
top: 15px;
right: 35px;
}
}
下面是我的html文件navbar.component.html:
<div id="myNav" class="overlay" *ngIf="displayNav">
<a href="javascript:void(0)" class="closebtn" (click)="closeNav()">×</a>
<div class="overlay-content">
<a href="#">About</a>
<a href="#">Services</a>
<a href="#">Clients</a>
<a href="#">Contact</a>
</div>
</div>
<h2>Fullscreen Overlay Nav Example</h2>
<p>Click on the element below to open the fullscreen overlay navigation menu.</p>
<p>In this example, the navigation menu will slide in, from left to right:</p>
<span style="font-size:30px;cursor:pointer" (click)="openNav()">☰ open</span>
当我点击☰ 打开它,只显示id=“myNav”的div区域,没有转换,我已经在class=“overlay”中设置了转换
但是我尝试用javascript n css在普通html中进行转换,它可以工作,我错过了什么?转换不起作用,因为
*ngIf
从DOM中删除了元素。你可以通过几种方式达到想要的效果。单击“使用”或“使用”时添加和删除活动类,尤其是transition(*void,animation(…)
我建议使用前者,因为经常消失和重新出现的元素不应该使用*ngIf
如果我做对了,这是您需要在代码中更改的唯一内容:
HTML
你能添加
!重要信息
请转到您的转换线路,然后重试。。i、 e.,转换:0.5s!重要的代码>我已经尝试了你的代码,它不起作用,当我点击按钮时,什么也没发生,我改变了我的区域,就像你说的那样,我添加了.overlay。积极的
import { Component } from '@angular/core';
@Component({
moduleId: module.id,
selector: 'app-navbar',
templateUrl: 'navbar.component.html',
styleUrls: ['navbar.component.css']
})
export class NavbarComponent {
public displayNav: boolean = false;
constructor() { }
openNav(){
this.displayNav = true;
console.log(this.displayNav);
}
closeNav(){
this.displayNav = false;
console.log(this.displayNav);
}
}
.overlay {
height: 100%;
width: 100%;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: rgb(0,0,0);
background-color: rgba(0,0,0, 0.9);
overflow-x: hidden;
transition: 0.5s;
}
<div id="myNav" class="overlay" [ngClass]="{active: displayNav}">
.overlay {
visibility: hidden;
opacity: 0
...
}
.overlay.active {
visibility: visible;
opacity: 1
}