如何使用/启用动画图标?

2024-02-02

有谁知道如何在 Angular Web 应用程序中使用/启用材料设计文档中显示的动画图标:https://material.io/design/iconography/animated-icons.html#usage https://material.io/design/iconography/animated-icons.html#usage


正如其他人所说,必须构建 Material Icon 网站上的示例。

然而,我找到了解决这个问题的方法,寻找有关如何对角度材质图标进行动画处理的指南,对于其他寻找相同内容的人,我有一个解决方案。默认动画可以自定义为 360 度旋转以外的其他动画。

基本上你可以创建一个在之间交换的组件mat-icon单击时或单击按钮等父元素时。

先决条件是您有一个安装了材质图标的角度材质应用程序。我用了角材料 8.

这是一个正在运行的 Stackblitzhttps://stackblitz.com/edit/angular-material-prototype-animated-icon https://stackblitz.com/edit/angular-material-prototype-animated-icon

mat-animated-icon.component.ts

import { Component, Input, OnInit } from '@angular/core';

@Component({
  selector: 'mat-animated-icon',
  templateUrl: './mat-animated-icon.component.html',
  styleUrls: ['./mat-animated-icon.component.scss']
})
export class MatAnimatedIconComponent implements OnInit {

  @Input() start: String;
  @Input() end: String;
  @Input() colorStart: String;
  @Input() colorEnd: String;
  @Input() animate: boolean;
  @Input() animateFromParent?: boolean = false;

  constructor() { }

  ngOnInit() {
    console.log(this.colorStart);
    console.log(this.colorEnd);
  }

  toggle() {
    if(!this.animateFromParent) this.animate = !this.animate;
  }

}

mat-animated-icon.component.scss

:host {
  font-family: 'Material Icons';
  font-weight: normal;
  font-style: normal;
  font-size: 24px;  /* Preferred icon size */
  display: inline-block;
  line-height: 1;
  text-transform: none;
  letter-spacing: normal;
  word-wrap: normal;
  white-space: nowrap;
  direction: ltr;

  /* Support for all WebKit browsers. */
  -webkit-font-smoothing: antialiased;
  /* Support for Safari and Chrome. */
  text-rendering: optimizeLegibility;

  /* Support for Firefox. */
  -moz-osx-font-smoothing: grayscale;

  /* Support for IE. */
  font-feature-settings: 'liga';

  /* Rules for sizing the icon. */
  &.md-18 { font-size: 18px; }
  &.md-24 { font-size: 24px; }
  &.md-36 { font-size: 36px; }
  &.md-48 { font-size: 48px; }

  /* Rules for using icons as black on a light background. */
  &.md-dark { 
    color: rgba(0, 0, 0, 0.54);

    &.md-inactive { color: rgba(0, 0, 0, 0.26); }
  }

  /* Rules for using icons as white on a dark background. */
  &.md-light { 
    color: rgba(255, 255, 255, 1);

    &.md-inactive { color: rgba(255, 255, 255, 0.3); }
  }

  .material-icons {
    transition: transform .5s;
    &.animate {
      transform: rotate(360deg);
    }
  }
}

mat-animated-icon.component.html

<mat-icon [ngClass]="{'animate' : animate}" color="{{animate ? colorEnd : colorStart}}" (click)="toggle()">{{animate ? end : start}}</mat-icon>

变量指令.ts

一些辅助指令

import { Directive, Input } from '@angular/core';

@Directive({
  selector: '[var]',
  exportAs: 'var'
})
export class VarDirective {

  @Input() var:any;

  constructor() { }

}

使用的组件示例

<button (click)="!this.disabled && iconAnimate10.var=!iconAnimate10.var" #iconAnimate10="var" var="'false'" mat-icon-button [disabled]="false" aria-label="Example icon-button with a heart icon">
<mat-animated-icon start="menu" end="close" colorStart="none" colorEnd="none" [animate]="iconAnimate10.var" animateFromParent="true"></mat-animated-icon>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何使用/启用动画图标? 的相关文章

随机推荐

  • 用于映射 5 到 7 张卡的组合的哈希函数

    参考原问题 优化扑克蒙特卡洛模拟的手牌评估算法 https stackoverflow com questions 22412698 optimizing hand evaluation algorithm for poker monte
  • 安卓本地搜索

    我正在尝试在我的活动中实现本地搜索 我已经向清单文件添加了适当的意图过滤器和元数据标记 但如果我单击 搜索 按钮 它会调用标准 Android 搜索框 我的问题是什么 清单文件
  • 我可以安全地将一个分支重新设置为另一个分支,然后掌握吗?

    我必须开发分支 我找到了分支B取决于分支的代码A 我想重新建立基础A into B这样我就可以继续发展B Soon A将被合并到master 前B 但是不是现在 然后 当我合并时B 它会破坏引用吗A重新基于它 我可以重新调整基础吗B on
  • 如何将类型类模式与子类型结合起来?

    假设我在 Scala 中使用类型类模式 这是我如何制作 C 类 类型类 Foo 的一部分 Welcome to Scala version 2 9 0 1 Java HotSpot TM 64 Bit Server VM Java 1 6
  • getter和setter方法有什么用? [复制]

    这个问题在这里已经有答案了 可能的重复 为什么要使用 getter 和 setter https stackoverflow com questions 1568091 why use getters and setters 谁能告诉我 g
  • 为什么“transform-es2015-modules-commonjs”在 Babel 6 中添加“use strict”?

    使用 Babel 6 我正在尝试not具有 use strict 在我编译的代码中 我发现这是 transform es2015 modules commonjs 插件 http babeljs io docs plugins transf
  • android共享首选项设置值

    我有偏好设置页面 它有 显示信息屏幕 字段 作为复选框 我还有信息页面 其中也应该有 再次显示 复选框 据我了解 我可以通过以下方式从偏好页面获取价值PreferencesManager getDefaultPreferences cont
  • 如何使用 aria2 保持目录结构?

    我需要同时下载文件 wget 不支持 所以我想尝试 aria2 但我在 aria2 中没有看到保留目录结构的选项 首先确定目录结构 然后构建并使用下载描述文件 aria2c i uri txt where uri txt可能包含 http
  • 关于如何为 Pygments 编写词法分析器的大量文档? [关闭]

    Closed 这个问题正在寻求书籍 工具 软件库等的推荐 不满足堆栈溢出指南 help closed questions 目前不接受答案 我有一本字典Stata http stata com 关键字和 Stata 语法的合理知识 我想花几个
  • 为什么 Log4Net 过滤器接收到评估器阈值之外的消息?

    我的 log4net 配置是这样的
  • AttributeError:模块“pydotplus”没有属性“Node”

    我正在尝试根据在 DataCamp 上找到的文章绘制我的决策树 https www datacamp com community tutorials decision tree classification python https www
  • 如何管理A-Frame使用的内存?

    我正在构建一个 Web 应用程序 它将 360 度图像加载到天空基元中 我在用着aframe react 总共有20 张360度的图片 只有一张img里面的资产a assets 一旦用户切换场景反应就会改变src资产的img并且场景将重新渲
  • 用数据填充 JList

    有没有人有关于如何填写的好的教程JList 在一个JPanel 与用户输入的数据 具体来说 我想将人员添加到选定的名册中 这是一个用一个填充它的问题吗 ArrayList 任何帮助将非常感激 创建一个 ListModel 来包装您的 jav
  • 在 Unity 2D 中移动简单对象

    我正在尝试移动一个简单的Object在 Unity 中 但我收到以下错误消息 cannot modify the return value of unityengine transform position because itar is
  • 如何以编程方式创建 SQL Server 视图的 ODBC 链接表并使其可编辑?

    当我使用向导创建到 SQL Server 的 DSN 连接时 我可以将其链接到视图 在这种情况下 Access 将其识别为可编辑表 但是 如果我使用 vba 代码对视图使用无 DSN 连接 方法 1 来自https support micr
  • 阿特金筛

    我一直在尝试学习生成素数的算法 并且在维基百科上发现了阿特金筛法 除了少数几个部分之外 我几乎理解该算法的所有部分 以下是问题 下面的三个二次方程是如何形成的 4x 2 y 2 3x 2 y 2 和 3x 2 y2 维基百科中的算法讨论了模
  • malloc(1) 的对齐要求是什么

    我听说成功调用malloc 返回适合任何类型对齐的指针 然而 要求这样做似乎毫无用处且浪费 malloc 1 返回一个指针 其对齐值大于1因为没有物体大于char可以存储到块中 对齐要求是什么malloc 1 malloc 2 etc 如果
  • 如何检测android内存不足?

    我的应用程序有很多图像 有时会由于内存不足而崩溃 我编写了在开发人员网站上找到的这个函数 public void onLowMemory 但问题是 在内存不足的情况下 这个函数永远不会被调用 我应该怎么做才能调用这个函数 当用户设备内存不足
  • 不再支持 android.useDeprecatedNdk=true

    I try to use OpenCv to build a facetracking camera app but I have a problem when I set up my OpenCv I have this error 我用
  • 如何使用/启用动画图标?

    有谁知道如何在 Angular Web 应用程序中使用 启用材料设计文档中显示的动画图标 https material io design iconography animated icons html usage https materi