To define an Angular Animation, we using DSL type of language. Means we are going to define few animations ('fadeIn', 'fadeOut').

Then we need to define something called 'transition', which use those animations. 'transition' defines from which state to which state, we should apply animation.

Last we need trigger to pick off the animation.

A little bit more coding needed and might not be easy to get the idea at once.

Remeber this

Trigger transitions to use animations to animate style

Read from 'Right' to 'Left', what we need is

  1. animation
  2. transitions
  3. trigger

1. Animations:

import {animation, style, animate, trigger, transition, useAnimation} from '@angular/animations';

/*
* DSL
* */
export const fadeIn = animation([
// start
style({
opacity: ,
'border-radius': '5px'
}),
// end
animate(
'1000ms',
style({
opacity: ,
})
)
]); export const fadeOut = animation(
animate(
'500ms',
style({opacity: })
)
);

2. Transition:

/*
* Transition
* */
export const fadeInOut = trigger('fadeInOut', [
transition('void => *', useAnimation(fadeIn)),
transition('* => void', useAnimation(fadeOut))
]);

From 'void' means 'nothing..', the ui element might not in the DOM yet.

To '*' any state, we use fadeIn animation.

From 'any state' to 'void', we use fadeOut animation.

And we also define 'fadeInOut' trigger to use in HTML:

  <au-modal [@fadeInOut] *auModalOpenOnClick="paymentModal" [body]="modalBody">

  </au-modal>

To see it works, we need to add animations in component:

import { Component } from '@angular/core';
import {fadeInOut} from './animations'; @Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
animations: [fadeInOut]
})
export class AppComponent {
title = 'app';
}
import {BrowserModule} from '@angular/platform-browser';
import {NgModule} from '@angular/core';
import {FormsModule} from '@angular/forms';
import {HttpModule} from '@angular/http'; import {AppComponent} from './app.component'; import {BrowserAnimationsModule} from '@angular/platform-browser/animations'; @NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
BrowserAnimationsModule,
....
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule {
}

[Angular] FadeIn and FadeOut animation in Angular的更多相关文章

  1. Jquery小例子:全选按钮、加事件、挂事件;parent()语法;slideToggle()语法;animate()语法;元素的淡入淡出效果:fadeIn() 、fadeOut()、fadeToggle() 、fadeTo();function(e):e包括事件源和时间数据;append() 方法

    function(e): 事件包括事件源和事件数据,事件源是指是谁触发的这个事件,谁就是事件源(div,按钮,span都可以是事件源),时间数据是指比如点击鼠标的事件中,事件数据就是指点击鼠标的左建或 ...

  2. [Angular 2 Router] Configure Your First Angular 2 Route

    Using the Angular 2 router requires defining routes, passing them in to the RouterModule.forRoot and ...

  3. 【Angular专题】——(1)Angular,孤傲的变革者

    目录 一. 漫谈Angular 二. 如果你还在使用Angularjs 三. 我计划这样学习Angular技术栈 一. 漫谈Angular Angular,来自Google的前端SPA框架,与Reac ...

  4. jQuery效果-----fadeIn()、fadeOut()、fadeToggle()、fadeTo()

    fadeIn(),fadeOut(),fadeToggle(),fadeTo() fadeIn()-----淡入已经隐藏的元素(把隐藏的被选元素渐渐显示出来). 语法:$(selector).fade ...

  5. [Angular] Use Angular components in AngularJS applications with Angular Elements

    When migrating AngularJS (v1.x) applications to Angular you have different options. Using Angular El ...

  6. 利用jquery的淡入淡出函数(fadeIn和fadeOut)--实现轮播

    首先说下,我在网上找的例子全是用的UL 实现,其实大可不必,只要是能包含img标签的HTML标签都可以做轮播效果.利用jquery的淡入淡出函数(fadeIn和fadeOut).废话也不多说,边上代码 ...

  7. Angular 从入坑到挖坑 - Angular 使用入门

    一.Overview angular 入坑记录的笔记第一篇,完成开发环境的搭建,以及如何通过 angular cli 来创建第一个 angular 应用.入坑一个多星期,通过学习官方文档以及手摸手的按 ...

  8. [从 0 开始的 Angular 生活]No.38 实现一个 Angular Router 切换组件页面(一)

    前言 今天是进入公司的第三天,为了能尽快投入项目与成为团队可用的战力,我正在努力啃官方文档学习 Angular 的知识,所以这一篇文章主要是记录我如何阅读官方文档后,实现这个非常基本的.带导航的网页应 ...

  9. Angular项目构建指南 - 不再为angular构建而犹豫不决(转)

    如果你不知道什么是Angular或者根本没听说过,那么我接下来所说的对你来说毫无益处,不过如果你打算以后会接触Angular或者干脆要涨涨姿势~读下去还是有点用的. Angular和它之前所出现的其余 ...

随机推荐

  1. [Python] Check for None (Null) in Python

    If you’ve used other programming languages, you may have learned that an empty object is not the sam ...

  2. 基于SVM的数据分类预測——意大利葡萄酒种类识别

    update:把程序源代码和数据集也附上http://download.csdn.net/detail/zjccoder/8832699 2015.6.24 --------------------- ...

  3. VS NuGet使用

    通过这个可以自动联网下载内容! 很方便! 工具->NuGet包管理工具->程序包管理器控制台

  4. Fragment-Transaction 源码分析

    概述 这篇文章的简要分析了Activity中的Transaction和add,replace等操作以及backstack的工作原理. 分析transaction源码的原因是因为我在写一个测试代码的时候 ...

  5. System.GC.Collect();//垃圾回收,回收没有正常关闭的http连接

    System.GC.Collect();//垃圾回收,回收没有正常关闭的http连接

  6. chattr---文件隐藏属性

  7. ping---测试主机之间网络的连通性

    ping命令用来测试主机之间网络的连通性.执行ping指令会使用ICMP传输协议,发出要求回应的信息,若远端主机的网络功能没有问题,就会回应该信息,因而得知该主机运作正常. 选项 -d:使用Socke ...

  8. mysql 数据库 存储数据类型

    int 类型的数据  可以在数据库里存成 char字符串类型的数据: 纯数字的字符串 可以在数据库里存储为 int的数据类型.

  9. 【习题 8-6 UVA - 1611】 Crane

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 想把数字i从位置j移动到位置i 可以这样. 假设mov(x,y)表示将(x..x+len/2-1)和(x+len/2..y)交换. ...

  10. 【Codeforces Round #427 (Div. 2) C】Star sky

    [Link]:http://codeforces.com/contest/835/problem/C [Description] 给你n个星星的坐标(xi,yi); 第i个星星在第t秒,闪烁值变为(s ...