我想要一个div从右边滑入角2使用CSS。
<div class="note" [ngClass]="{'transition':show}" *ngIf="show">
<p> Notes</p>
</div>
<button class="btn btn-default" (click)="toggle(show)">Toggle</button>
如果我只使用[ngClass]来切换类和使用不透明度,我就能正常工作。但是li不想从一开始就呈现该元素,所以我首先用ngIf“隐藏”它,但是之后的过渡就不起作用了。
.transition{
-webkit-transition: opacity 1000ms ease-in-out,margin-left 500ms ease-in-out;
-moz-transition: opacity 1000ms ease-in-out,margin-left 500ms ease-in-out;
-ms-transition: opacity 1000ms ease-in-out,margin-left 500ms ease-in-out ;
-o-transition: opacity 1000ms ease-in-out,margin-left 500ms ease-in-out;
transition: opacity 1000ms ease-in-out,margin-left 500ms ease-in-out;
margin-left: 1500px;
width: 200px;
opacity: 0;
}
.transition{
opacity: 100;
margin-left: 0;
}
更新4.1.0
柱塞
另请参见https://github.com/angular/angular/blob/master/changelog.md#400-rc1-2017-02-24
更新2.1.0
柱塞
有关更多详细信息,请参阅Angular.io处的动画
import { trigger, style, animate, transition } from '@angular/animations';
@Component({
selector: 'my-app',
animations: [
trigger(
'enterAnimation', [
transition(':enter', [
style({transform: 'translateX(100%)', opacity: 0}),
animate('500ms', style({transform: 'translateX(0)', opacity: 1}))
]),
transition(':leave', [
style({transform: 'translateX(0)', opacity: 1}),
animate('500ms', style({transform: 'translateX(100%)', opacity: 0}))
])
]
)
],
template: `
<button (click)="show = !show">toggle show ({{show}})</button>
<div *ngIf="show" [@enterAnimation]>xxx</div>
`
})
export class App {
show:boolean = false;
}
原件
*ngif
在表达式变为false
时从DOM中删除元素。不能对不存在的元素进行转换。
改用hidden
:
<div class="note" [ngClass]="{'transition':show}" [hidden]="!show">