Angular 2 惊人的动画

标签 angular animation angular-animations

Angular 2 RC2 刚出来,我想知道它是否已经支持 *ngFor 的交错动画? DSL 语言文档提到 groupsequence 但没有任何形式的交错?

RC2中不包含交错动画吗?

最佳答案

我不确定我是否同意 Günter 的观点,即 ng-conf 功能是在最新的 RC.3 中还是在 RC.4 版本中。交错功能会非常好,但目前看起来不像是为 RC.5 设计的。它肯定会出现在 Angular 2 Final 版本中,您可以在这个动画跟踪中看到 ticket .话虽这么说,但我确实为我的应用程序创建了一个解决方法,我愿意分享。可能有更简单的方法,但这很有效:

@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 });
    }
}

就像我说的可能不是最简单的方法,但它对我有用。希望对你有帮助!

*帮助者:What is the JavaScript version of sleep()?

关于Angular 2 惊人的动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37880525/

相关文章:

angular - Angular 4 上的动画似乎没有过渡效果

Angular 动画在 IE edge 中不起作用

android - 将数据从 Angular6 微应用程序传递到移动应用程序

ios - 暂停一个动画同时保持另一个动画 — BAFluidView Swift

html - 显示 10 秒后反复淡入淡出两个图像

reactjs - 如何在react-三纤中n秒后停止useFrame

http - 将数据从使用 http 的 Angular 2 服务传递到组件

angular - 使用 Webpack 5 模块联合提供样式和 Assets

angular - 在 Angular 5 http 请求中使用 observable 有什么好处?

angular - 如何在 Angular 6 中创建震动动画?