Declares a key/value object containing CSS properties/styles that can then be used for an animation state
, within an animation sequence
, or as styling data for calls to animate()
and keyframes()
.
声明一个包含 CSS 属性/样式的键值对象,可在动画序列中用作动画状态(state
),或在调用 animate()
和 keyframes()
时作为传入的样式数据。
style(tokens: '*' | { [key: string]: string | number; } | Array<'*' | { [key: string]: string | number; }>): AnimationStyleMetadata参数
tokens | A set of CSS styles or HTML styles associated with an animation state. The value can be any of the following: 一组 CSS 样式或与动画状态相关联的 HTML 样式。 它可以是下列值之一: A key-value style pair associating a CSS property with a value. 一个键值对,把 CSS 属性和值关联起来。 An array of key-value style pairs. 一组表示样式的键值对。 An asterisk (*), to use auto-styling, where styles are derived from the element being animated and applied to the animation when it starts. 一个星号(* ),表示自动样式,其样式值会在应用此样式的时刻从目标元素中取得,并用作动画参数。
Auto-styling can be used to define a state that depends on layout or other environmental factors. 自动样式可用于定义一个需要依赖布局或其它环境因素的状态。 |
返回值
AnimationStyleMetadata
: An object that encapsulates the style data.
一个封装了样式数据的对象。
使用说明
The following examples create animation styles that collect a set of CSS property values:
下面的例子创建了一些带有一组 CSS 属性值的动画样式:
// string values for CSS properties style({ background: "red", color: "blue" }) // numerical pixel values style({ width: 100, height: 0 })The following example uses auto-styling to allow a component to animate from a height of 0 up to the height of the parent element:
下面的例子使用了自动样式,以允许此动画将组件的高度从 0 逐渐增长到其父元素的高度:
style({ height: 0 }), animate("1s", style({ height: "*" }))