显示隐藏的离子3动画

时间:2017-07-18 00:58:22

标签: angular animation ionic3

我有一个离子卡,根据布尔值显示或隐藏的元素很少。

一切正常,但变化非常快,所以没有很好的用户体验。

离子卡看起来像:

    <ion-card>
                            <img *ngIf="item.showActions == false" class="img-card" src="{{item.imgUrl}}"/>
                            <ion-card-content>
                                <ion-card-title>{{item.msg}}</ion-card-title>
                            </ion-card-content>
                            <ion-grid *ngIf="item.showActions == true" no-padding style="border-top: 0.5px solid #E7E7E7;border-bottom: 1px solid #E7E7E7">
                                <ion-row padding><ion-col><p>For this news you can take following actions</p></ion-col></ion-row>
                                <ion-row text-center>
                                        <ion-col>
                                        <br/>
                                    <button ion-button clear small  icon-left (click)="presentPopover($event)">Show
                                    </button>
                                     <h2>Create Task</h2>
                                     <br/>
                                </ion-col>
                                </ion-row>
</ion-grid>
<ion-card>

所以item.showActions是一个布尔值,我根据某些动作进行翻转。我希望这种过渡顺利发生,如翻转或淡化。

1 个答案:

答案 0 :(得分:4)

你可以使用角度动画来做到这一点。淡出/淡出元素的示例:

import { trigger, state, style, animate, transition } from '@angular/animations';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html',
  animations: [
    trigger('visibilityChanged', [
      state('shown', style({ opacity: 1 })),
      state('hidden', style({ opacity: 0 })),
      transition('* => *', animate('500ms'))
    ])
  ]
})

export class HomePage {
  visibility: string = 'hidden';
  ...
}

在你的HTML中:

<div [@visibilityChanged]="visibility" style="opacity: 0">test</div>

可以在此处找到更多信息:https://angular.io/guide/animations