javascript - How to use animation on angular 8?
问题描述
I am trying to use a simple rotation animation. I get the style done, but it's happens immediately, without any actual animation.
HTML:
<img class="icon" [@rotation]="liked? 'rotate' : 'straight'" (click)="liked = ! liked" src="mySource"/>
TS:
import { Component, OnInit, Input } from '@angular/core';
import {trigger, state, style, animate, transition,} from '@angular/animations';
@Component({
selector: 'app-info-window',
animations: [
trigger('rotation', [
state('straight', style({ transform: 'rotate(0)' })),
state('rotate', style({ transform: 'rotate(180deg)' })),
transition('rotated => straight', animate('400ms ease-out')),
transition('straight => rotated', animate('400ms ease-in'))
]),
],
templateUrl: './info-window.component.html',
styleUrls: ['./info-window.component.css']
})
export class InfoWindowComponent implements OnInit {
liked = false;
I imported the BrowserAnimationsModule in the app.module. What am i doing wrong?
解决方案
您在转换定义中有错字。它应该是
transition('rotate => straight', animate('400ms ease-out')),
transition('straight => rotate', animate('400ms ease-in'))
注意rotate
而不是rotated
.
推荐阅读
- python - 将 apply 函数用于带有参数的 pandas 数据框
- hadoop - 如何衡量 Google Cloud Dataproc 中的高可用性
- python - 用于多个结果的 Django ORM filter()
- php - 如何使用 php 连接 Ms Access Db
- android - 库项目中的 Dagger2 + ActivityInjection + AndroidXTest/Espresso/RoboElectric
- python - python将base64解码成json文件
- java - 转换地图
> 到地图 >,使用 Java 8 流。我这样做了,但是没有 for 循环怎么做 - powershell - 如果用户属于这个组,显示这个,如果不是,显示这个
- javascript - React 和 React Router 中的子域路由
- python - 在python中使用tabula从PDF中提取完整的表格