1分钟入门angular动画效果animations,敲简单滴哟~~☺

简介: 1分钟入门angular动画效果animations,敲简单滴哟~~☺

运行代码创建component


ng g c animate-test



然后在app.module.ts做如下引入


分别是下面两行,自行引入

import {BrowserAnimationsModule} from '@angular/platform-browser/animations';//注意这个很重要
 
 
BrowserAnimationsModule,//注意这个很关键,没有引入动不起来

接下来傻瓜式拷贝代码

animate-test.component.html

<button (click)="toggle()">{{yellowOrGreen ? '你黄了!':'你被绿了!'}}</button>
<div [@openClose]="yellowOrGreen ? 'yellow' : 'green'" >
  <p>{{yellowOrGreen ? '你黄了!':'你被绿了!'}}</p>
</div>

animate-test.component.ts

import {Component, OnInit} from '@angular/core';
import {trigger, state, style, animate, transition} from '@angular/animations';
 
@Component({
  selector: 'app-animate-test',
  templateUrl: './animate-test.component.html',
  styleUrls: ['./animate-test.component.css'],
  animations: [
    trigger('openClose', [
      state('yellow', style({height: '50px', color: 'black', backgroundColor: 'yellow'})),
      state('green', style({height: '100px', color: 'white', fontSize: '40px', fontWeight: 'bold', backgroundColor: 'green'})
      ),
      transition('yellow=>green', [animate('0.3s')]),
      transition('green=>yellow', [animate('0.5s')]),
      // transition('yellow <=> green', [animate('1s')]) //双箭头可以指定两个状态互相转场
    ])
  ]
})
export class AnimateTestComponent implements OnInit {
  public yellowOrGreen = true;
 
  ngOnInit() {
  }
 
  public toggle() {
    this.yellowOrGreen = !this.yellowOrGreen;
  }
}

然后别忘了在app-routing.module.ts路由里面加入这个组件页面哟~

import {AnimateTestComponent} from "./components/animate-test/animate-test.component";
 
  {
    path: 'animate-test',
    component: AnimateTestComponent,//同步加载
  },

然后ng start --open跑起来吧亲~

注意访问地址大概是http://localhost:4200/animate-test

点击按钮之后就


相关文章
|
JavaScript 前端开发 Java
【Angular教程】路由入门
【Angular教程】路由入门
300 0
【Angular教程】路由入门
|
5月前
1分钟入门angular动画效果animations,敲简单滴哟~~
1分钟入门angular动画效果animations,敲简单滴哟~~
1分钟入门angular动画效果animations,敲简单滴哟~~
|
监控 JavaScript
angular之入门基础
angular之入门基础
112 0
angular之入门基础
|
JavaScript
Angular入门,开发环境搭建,使用Angular CLI创建你的第一个Angular项目
Angular入门,开发环境搭建,使用Angular CLI创建你的第一个Angular项目
320 0
Angular入门,开发环境搭建,使用Angular CLI创建你的第一个Angular项目
|
API
Angular 2.x折腾记 :(10) 初步了解动画,以及一步一步写个动画效果
过渡动画这东西,在现代开发中是必不可少的,死板和酷炫与之息息相关;
105 0
|
前端开发 JavaScript 编译器
|
前端开发 JavaScript 开发者
最新的Angular 5 入门与提高
一、概述 尽管被称为Angular5,实际上它只是这个诞生于2012年的前端框架的的第四个版本: 看起来差不多半年就发布一个新版本,不过实际上从重写的版本2开始,开发 接口与核心思想就稳定下来了,并基本保持着与前序版本的兼容性。
1787 0
|
Python
进入DRF和ANGULAR的整合学习,这三篇入门内容一定要学好的
看来,DJANGO的模板功能是无法用啦, 学着用ANGLUAR的SERVICE,MODULE,CONTROLLER啦。。。 http://engineroom.trackmaven.com/blog/getting-started-drf-angularjs-part-1/ http://engineroom.
987 0
|
23天前
|
存储 前端开发 API
浅谈 Angular 应用前端消息显示机制的一个实际需求
浅谈 Angular 应用前端消息显示机制的一个实际需求
12 0

热门文章

最新文章