Angular 2 Staggering Animation

旧时模样 提交于 2019-12-01 18:59:29
wootencl

I'm not sure if I agree with Günter that the ng-conf features are in the newest RC.3 or for that matter in the RC.4 release. A stagger feature would be excellent but as of current that doesn't look like it's slated for RC.5. It will definitely be in the Angular 2 Final release as you can see on this animation tracking ticket. With that being said though I did create a workaround for my application I would be willing to share. There might be an easier approach but this works:

@Component({
    selector: 'child',
    templateUrl: `<div @fadeIn="state">This is my content</div>`,
    animations: [
        trigger('fadeIn', [
            state('inactive', style({opacity:0})),
            state('active', style({opacity:1)})),
            transition('inactive => active', [
                animate('500ms ease-in')
            ])
        ])
    ]
})
export class Child implements OnInit {
    @Input() delay;

    constructor() {
        this.state = 'inactive';
    }
    ngOnInit() {
        this.sleep(this.delay).then(() => {
            this.state = 'active';
        };
    }
    // HELPER*
    sleep(time) {
        return new Promise((resolve) => setTimeout(resolve, time));
    }
}

@Component({
    selector: 'parent',
    templateUrl: `
        <div *ngFor="let child of children">
            <child [delay]="child.delay"></child>
        </div>
    `
})
export class Child implements OnInit {
    constructor() {
        this.children = [];
        this.children.push({ delay: 600 });
        this.children.push({ delay: 1200 });
    }
}

Like I said maybe not the simplest way but it works for me. Hope it helps you!

*HELPER: What is the JavaScript version of sleep()?

They are working on it, as we can see here: https://www.youtube.com/watch?v=Hr4IKlr9mhg&feature=youtu.be&t=10m50s

But I think it was not released yet... We need to wait a little more :-(

Here there is the examples that we see in the video... but I don't know if this is a stable version... at your own risk https://github.com/matsko/ng-conf-demos

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!