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

    1.先做一个简单的例子

     => 

      定义一个div 从open渐变成closed

      ts:定义一个触发器 openClose,有两个状态 open 和 closed,均有对应的样式,再定义装换函数 transition

    import { Component, OnInit} from '@angular/core';
    // 动画函数
    import { trigger, state, style, animate, transition } from '@angular/animations';
    @Component({
      selector: 'app-study',
      templateUrl: './study.component.html',
      styleUrls: ['./study.component.scss'],
      animations: [
        trigger('openClose', [
          state('open', style({
            height: '200px',
            opacity: 1,
            backgroundColor: 'yellow'
          })),
          state('closed', style({
            height: '100px',
            opacity: 0.5,
            backgroundColor: 'green'
          })),
          transition('open => closed', [animate('1s')]),
          transition('closed => open', [animate('0.5s')]),
        ]),
      ],
    })
    export class StudyComponent implements OnInit {
      isOpen = true;
      constructor() {
      }
    
      ngOnInit() {
      }
    
      toggle() {
        this.isOpen = !this.isOpen;
      }
    }

      html:@后面指定触发器 并赋值状态

    <div [@openClose]="isOpen? 'open':'closed'" (click)="toggle()">
      <p>The box is now {{isOpen?'Open':'Closed'}}!</p>
    </div>
  • 相关阅读:
    Centos7使用systemd 管理elasticsearch,创建elasticsearch服务
    nginx日志切割的2种方法
    sudo linux
    redis 重启不了
    类与对象
    用Python写一个小的购物车
    包的使用
    Python模块简介
    zookeeper & Dubbo
    迭代器 & 生成器
  • 原文地址:https://www.cnblogs.com/wskxy/p/10569978.html
Copyright © 2011-2022 走看看