angular 动画 query用法

query API 翻译

function query(selector: string, animation: AnimationMetadata | AnimationMetadata[], options: AnimationQueryOptions | null = null): AnimationQueryMetadata;

描述

query是一个动画特效function被用于angular的动画DSL领域语言
query()被用于找到当前元素内部一个或多个元素,使其顺序执行动画。
已提供好的动画步骤被应用到序列元素上(缺省下,提供一个数组,它被看成一个动画序列)

用法

query()通过 element.querySelectorAll 来收集多个元素和工作。
另一个参数对象可以限制被收集的个数。

query('div', [
  animate(...),
  animate(...)
], { limit: 1 })

query(), by default, will throw an error when zero items are found. If a query has the optional flag set to true then this error will be ignored.
query(),缺省下,没有元素被找到时,返回error。如果optional设置为true,则忽略error

query('.some-element-that-may-not-be-there', [
  animate(...),
  animate(...)
], { optional: true })

特殊选择器

这种语法可以帮助筛选出特殊的元素
包括:
- 新插入 新移除元素 使用 query(“:enter”)/query(“:leave”)
- 当前所有正在动的元素 使用 query(“:animating”)
- 包含一个trigger动画触发器的元素 使用 query(“@triggerName”)
-包含动画触发器的所有元素 使用query(“@*”)
- 将当前元素包含到动画序列中 使用query(“:self”)
这些查询结果都可以合并成一个大字符串的写法

query(':self, .record:enter, .record:leave, @subTrigger', [...])

实例

@Component({
  selector: 'inner',
  template: `
    <div [@queryAnimation]="exp">
      <h1>Title</h1>
      <div class="content">
        Blah blah blah
      </div>
    </div>
  `,
  animations: [
   trigger('queryAnimation', [
     transition('* => goAnimate', [
       // hide the inner elements
       query('h1', style({ opacity: 0 })),
       query('.content', style({ opacity: 0 })),

       // animate the inner elements in, one by one
       query('h1', animate(1000, style({ opacity: 1 })),
       query('.content', animate(1000, style({ opacity: 1 })), ])
   ])
 ]
})
class Cmp {
  exp = '';

  goAnimate() {
    this.exp = 'goAnimate';
  }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值