简体   繁体   English

angular2组件中的多个动画触发器

[英]Multiple animation triggers in angular2 Component

I would like to define multiple animation triggers in one component. 我想在一个组件中定义多个动画触发器。 Is this possible? 这可能吗?

For example one for entering the scene and one for hover. 例如,一个用于进入场景,一个用于悬停。 Or do I need to define two components (parent child) for this case? 或者我是否需要为此案例定义两个组件(父子组件)?

item.compoennt.ts item.compoennt.ts

// removed the import and class part for better readability

@Component({
  selector: 'item',
  templateUrl: './item.template.html',
  styleUrls: ['./item.style.scss'],
  animations: [
    // page load animation 
    trigger('slideIn', [
        state('in', style({
            opacity: 1,
            transform: 'translateY(0)'
        })),
        transition('void => *', [
            style({
                transform: 'translateY(100%)',
                opacity: 0
            }),
            animate('0.5s 100ms ease-in')
      ])
    ]),


    // <--- this fails
    // hover animation
    trigger('fadeIn', [
      state('over', style({
            opacity: 1
        })),
        transition('void => *', [
            style({
                opacity: 0
            }),
            animate('0.5s 100ms ease-in')
    ])
  ],
})

item.template.html item.template.html

<div class="item" [@slideIn]="enterState">

    <div class="info">
        SOME INFO
    </div>
    <div class="info-on-hover" [@fadeIn]="hoverState">
        SOME INFO 
    </div>
</div>  

Oh and someone should create the tag "angular2-animation" 哦,有人应该创建标签“angular2-animation”

Regards 问候

I would like to define multiple animation triggers in one component. 我想在一个组件中定义多个动画触发器。 Is this possible? 这可能吗?

Yes you can have as many triggers as you need. 是的,您可以根据需要拥有尽可能多的触发器。

You can also have multiple states in one trigger not just two. 您还可以在一个触发器中具有多个状态,而不仅仅是两个。 So you can for example have a 'enter' state and a 'hover' state with different transitions between the states. 因此,您可以例如具有“进入”状态和“悬停”状态,状态之间具有不同的转换。

For example: 例如:

state('in', style({opacity: 1,
            transform: 'translateY(0)'
        })),
state('hover', style({background: 'red'}),
transition('* <=> hover', animate('200ms ease-in'))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM