zoukankan      html  css  js  c++  java
  • Angular动画

    animation

    // 使用方法
    git clone https://git.oschina.net/mumu-osc/learn-component.git
    cd learn-component
    git pull origin animation
    npm install 
    ng serve
    

    写法

    // fly-in.ts
    import { trigger, state, style, transition, animate, keyframes } from '@angular/animations';
    
    export const flyIn = trigger('flyIn', [
        transition('void => *', [
            animate(3000, keyframes([
                style({ opacity: 0, transform: 'translateX(-100%)', offset: 0 }),
                style({ opacity: 1, transform: 'translateX(25px)', offset: 0.3 }),
                style({ opacity: 1, transform: 'translateX(0)', offset: 1.0 })
            ]))
        ]),
        transition('* => void', [
            animate(300, keyframes([
                style({ opacity: 1, transform: 'translateX(0)', offset: 0 }),
                style({ opacity: 1, transform: 'translateX(-25px)', offset: 0.7 }),
                style({ opacity: 0, transform: 'translateX(100%)', offset: 1.0 })
            ]))
        ])
    ]);
    

    使用

    <div class="panel panel-primary" [@flyIn]="state">
      <div class="panel-heading">飞入效果</div>
      <div class="panel-body">
        飞入效果
      </div>
    </div>
    
    import { Component, OnInit } from '@angular/core';
    import { flyIn } from '../animations/fly-in';
    
    @Component({
      selector: 'app-test-fly-in',
      templateUrl: './test-fly-in.component.html',
      styleUrls: ['./test-fly-in.component.css'],
      animations:[flyIn]
    })
    export class TestFlyInComponent implements OnInit {
      state:string;
    
      constructor() { }
    
      ngOnInit() {
      }
    
    }
    

    注意

    需要在主模块中引入BrowserAnimationsModule

    import { BrowserModule } from '@angular/platform-browser';
    import { NgModule } from '@angular/core';
    import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
    
    import { AppComponent } from './app.component';
    import { TestFlyInComponent } from './test-fly-in/test-fly-in.component';
    
    @NgModule({
      declarations: [
        AppComponent,
        TestFlyInComponent
      ],
      imports: [
        BrowserModule,
        BrowserAnimationsModule
      ],
      providers: [],
      bootstrap: [AppComponent]
    })
    export class AppModule { }
    
  • 相关阅读:
    elasticsearch-head插件基本使用
    Windows包管理工具-Chocolatey
    php-fpm常用操作
    nginx之日志处理
    进程管理工具之supervisor(完整版)
    Elasticsearch之常见问题
    支付宝支付功能接入(PC)
    UnityWebRequest 高级API常用的操作
    UnityWebRequest
    logback中使用日期做为文件目录
  • 原文地址:https://www.cnblogs.com/zheng-chuang/p/7418589.html
Copyright © 2011-2022 走看看