我想在点击的同时发射两个动画 . 动画触发器使用相同的状态,一个放在外部父div上,另一个嵌套在这个div中 . 进行样式更改,但转换仅应用于父组件 . 我在父动画中使用了animateChild而没有运气 . 如何应用父元素和子元素的动画?
animations.ts
import {
trigger,
state,
style,
transition,
animate,
query,
group,
animateChild,
} from "@angular/animations";
export const Animations = {
animations: [
trigger("expansionTrigger", [
state(
"true",
style({
height: "*"
})
),
state(
"false",
style({
height: "0",
display: "none"
})
),
transition("false <=> true", [
group([
query("@colExpansion", [animateChild()]),
animate("3s ease")
])
])
]),
trigger("colExpansion", [
state(
"true",
style({
"-webkit-box-flex": "0",
flex: "0 0 66.66667%",
"max-width": "66.66667%"
})
),
state(
"false",
style({
"flex-basis": "0",
"-webkit-box-flex": "1",
"flex-grow": "1",
"max-width": "100%"
})
),
transition("false <=> true", animate(3))
])
]
};
body.component.ts
import { Component, Input } from '@angular/core';
import { Animations } from '../animations';
@Component({
selector: 'app-body',
templateUrl: './body.component.html',
styleUrls: ['./body.component.css'],
animations: Animations.animations
})
export class BodyComponent {
@Input() isExpanded: string;
}
body.component.html
<div [@expansionTrigger]="isExpanded === 'true' ? 'true' : 'false'">
<div [@colExpansion]="isExpanded === 'true' ? 'true' : 'false'">
</div>
</div>
1 回答
我做了一个工作演示 . 我做了自己的风格,因为我没有理解这个组件的目的 . 您可以轻松地根据您的风格进行调整......
animations.ts
body.component.ts
body.component.scss
body.component.html