在官方教程的帮助下,我在@ angular /动画中迈出了第一步。我添加了reqired库,并创建了我的第一个动画。我已经知道过渡和状态是什么。我可以创建简单的动画(改变背景颜色和变化分量的大小,如何使用Angular2动画更改弹性布局?
我用@角/柔性布局库在我的项目,以创造整洁的页面布局和来这里的问题:。我怎样才能动画增加和减少的元素的宽度我的Flex布局例如:
我有我的网页上3 “列”:
- 在第一状态它们的宽度是:38%,52%,容器
- 和在第二状态它们的宽度是10%:50%,25%,25%
只是就像在图片中一样(这些是其他状态下的相同列)
问题:我应该如何制作一个转换动画来更改列的宽度变化?我可以使用哪些方法和属性?什么代码应该看起来像?
=====
@EDIT:
我公布我的HTML代码片段呈现哪个属性我想改变(fxFlex)
app.component.html
<div class="flex-container"
fxLayout="row"
fxLayout.xs="column"
fxLayoutAlign="end none"
fxLayoutAlign.xs="end none" class="container-style">
<!-- first column -->
<div class="flex-item" fxFlex="38%" fxShow.xs="false" class="one" [@oneState]="state"></div>
<!-- second column -->
<div class="flex-item" fxFlex="52%" class="two" [@twoState]="state"></div>
<!-- third column -->
<div class="flex-item" fxFlex class="three"></div>
</div>
对于app.component.ts
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
animations: [
trigger('oneState', [
state('inactive', style({
//I have no idea what I should use to change fxFlex attribute!
//Style? Maybe, something else?
})),
state('active', style({
//I have no idea...
})),
transition('inactive => active', animate('100ms ease-in')),
transition('active => inactive', animate('100ms ease-out'))
]),
trigger('twoState', [
state('inactive', style({
//I have no idea what I should use to change fxFlex attribute!
//Style? Maybe, something else?
})),
state('active', style({
//I have no idea...
})),
transition('inactive => active', animate('100ms ease-in')),
transition('active => inactive', animate('100ms ease-out'))
]),
]
})
export class AppComponent {
title = 'app works!';
state: string = 'inactive';
toggleMove() {
this.state = (this.state === 'inactive' ? 'active' : 'inactive');
console.log(this.state);
}
}
我知道,我可以改变风格格的简单方法。但我不想改变风格。我想更改元素的fxFlex属性。
任何人都可以帮到我吗?可能吗??
哦,那你就不需要使用角动画:d – n00dl3
呦n00dl3:您间d谢谢在主题中。我投了你的答案,但它不是解决方案。它仅在我关闭项目中的FlexLayoutModule时才起作用。我写过,我想使用@ angular/flex-layout库来设计我的项目的页面布局。你有另外的想法吗? –
你可以用'[FxFlex]'上的选择器来做到这一点,除了你需要直接在元素而不是样式表上设置样式之外,它几乎是相同的。 – n00dl3