微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

angular 过度动画

1.在所需过度ts中引入

import {trigger, style, animate, transition, state} from '@angular/animations'

在app.module.ts 引入

import { browserAnimationsModule } from '@angular/platform-browser/animations';

2.设定过度方案

trigger(‘动画组名’[
  state(‘动画名’,style({写CSS}),
  state(‘动画名2’,style({写CSS})
transition(‘动画名=>动画名2’,animate(‘运动时间’))
])

3.所需元素绑定触发

[@动画组名]="判断条件?‘动画名’:‘动画名2’"
  或者@动画组名

案例

html

<div style="height: 30px;width: 100px;border: 1px solid cornflowerblue" (mouseenter)="mousein()"  (mouseleave)="mouSEOut()"></div>

<div style="position: absolute" *ngIf="isshow" @myInsertRemoveTrigger  >
  <ng-content class="mydiv"></ng-content>
</div>

ts代码

import {Component, OnInit} from '@angular/core';
import {trigger, style, animate, transition, state} from '@angular/animations'


@Component({
  selector: 'app-test',
  templateUrl: './test.component.html',
  styleUrls: ['./test.component.css'],
  animations: [
    trigger('myInsertRemoveTrigger', [
      transition(':enter', [
        style({opacity: 0}),
        animate('100ms', style({opacity: 1})),
      ]),
      transition(':leave', [
        animate('100ms', style({opacity: 0}))
      ])
    ]),
  ],
})
export class TestComponent implements OnInit {

  constructor() {
  }

  ngOnInit(): void {
  }

  isshow = false

  mousein() {
    this.isshow = true
  }

  mouSEOut() {
    this.isshow = false
  }
}

别忘了在app.module.ts中引入

import { browserAnimationsModule } from '@angular/platform-browser/animations';

 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐