【问题标题】:ionic 3 animate while show hide离子3动画同时显示隐藏
【发布时间】:2017-07-18 09:29:21
【问题描述】:

我有一张离子卡,它几乎没有基于布尔值显示或隐藏的元素。

一切正常,但变化非常迅速,因此用户体验不佳。

离子卡看起来像:

    <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 是一个布尔值,我根据一些动作翻转它。我希望这种过渡能够像翻转或淡出一样顺利进行。

【问题讨论】:

    标签: angular animation ionic3


    【解决方案1】:

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

    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

    【讨论】:

    • 我的代码的哪一部分需要为 div 标签更改?
    • 这只是一个例子,你可以将[@visibilityChanged]="visibility"添加到你想要动画的元素中
    • 当我粘贴你的代码时,我的屏幕上什么都没有,但是当我删除了内联样式的不透明度时,它就起作用了。你能解释一下这种风格背后的意图吗??
    • 就我而言,我希望在页面加载时隐藏元素。我想这就是它存在的原因。
    猜你喜欢
    • 2018-03-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-25
    • 2016-02-02
    • 1970-01-01
    • 1970-01-01
    • 2010-11-04
    • 1970-01-01
    相关资源
    最近更新 更多