Skip to content

d3-ease

示例 · 缓动 是一种扭曲时间以控制动画中表观运动的方法。它最常用于 慢入慢出。通过缓动时间,动画过渡 更加平滑,并且表现出更合理的运动。

本模块中的缓动类型实现了ease方法,该方法接受归一化时间 t 并返回相应的“缓动”时间 。归一化时间和缓动时间通常都在 [0,1] 范围内,其中 0 代表动画的开始,1 代表动画的结束;一些缓动类型,如 easeElastic,可能返回略微超出该范围的缓动时间。一个好的缓动类型应当在 t = 0 时返回 0,在 t = 1 时返回 1。

🌐 The easing types in this module implement the ease method which takes a normalized time t and returns the corresponding “eased” time . Both the normalized time and the eased time are typically in the range [0,1], where 0 represents the start of the animation and 1 represents the end; some easing types, such as easeElastic, may return eased times slightly outside this range. A good easing type should return 0 if t = 0 and 1 if t = 1.

这些缓动类型在很大程度上基于Robert Penner的工作。

🌐 These easing types are largely based on work by Robert Penner.

缓动(t)

🌐 ease(t)

给定指定的归一化时间 t,通常在 [0,1] 范围内,返回“缓动”时间 ,通常也在 [0,1] 范围内。0 表示动画开始,1 表示动画结束。一个好的实现会在 t = 0 时返回 0,在 t = 1 时返回 1。例如,要应用 easeCubic 缓动:

🌐 Given the specified normalized time t, typically in the range [0,1], returns the “eased” time , also typically in [0,1]. 0 represents the start of the animation and 1 represents the end. A good implementation returns 0 if t = 0 and 1 if t = 1. For example, to apply easeCubic easing:

js
const te = d3.easeCubic(t);

要应用自定义 elastic 缓动,请在动画开始之前创建你的缓动函数:

🌐 To apply custom elastic easing, create your easing function before the animation starts:

js
const ease = d3.easeElastic.period(0.4);

然后在动画期间,应用缓动函数:

🌐 Then during the animation, apply the easing function:

js
const te = ease(t);

另请参见 transition.ease

🌐 See also transition.ease.

线性缓动

🌐 easeLinear

来源 · 线性缓动;恒等函数;linear(t) 返回 t

easePoly

来源 · easePolyInOut 的别名。

easePolyIn

多项式缓动;将 t 提升到指定的指数。如果未指定指数,默认为3,相当于easeCubicIn

🌐 Polynomial easing; raises t to the specified exponent. If the exponent is not specified, it defaults to 3, equivalent to easeCubicIn.

easePolyOut

反向多项式缓动;等价于 1 - easePolyIn(1 - t)。如果未指定指数,则默认为 3,等价于 easeCubicOut

🌐 Reverse polynomial easing; equivalent to 1 - easePolyIn(1 - t). If the exponent is not specified, it defaults to 3, equivalent to easeCubicOut.

easePolyInOut

对称多项式缓动;对 t 在 0–0.5 范围内使用 easePolyIn,在 0.5–1 范围内使用 easePolyOut。如果未指定指数,默认为 3,相当于 easeCubic

🌐 Symmetric polynomial easing; scales easePolyIn for t in 0–0.5 and easePolyOut for t in 0.5–1. If the exponent is not specified, it defaults to 3, equivalent to easeCubic.

easePoly.exponent(e)

返回一个具有指定指数 e 的新多项式缓动。例如,要创建 easeLineareaseQuadeaseCubic 的等效项:

🌐 Returns a new polynomial easing with the specified exponent e. For example, to create equivalents of easeLinear, easeQuad, and easeCubic:

js
const linear = d3.easePoly.exponent(1);
const quad = d3.easePoly.exponent(2);
const cubic = d3.easePoly.exponent(3);

easeQuad

来源 · easeQuadInOut 的别名。

easeQuadIn

二次缓动;等同于 easePolyIn.指数(2)。

🌐 Quadratic easing; equivalent to easePolyIn.exponent(2).

easeQuadOut

反向二次缓动;等同于 1 - easeQuadIn(1 - t)。也等同于 easePolyOut.exponent(2)。

🌐 Reverse quadratic easing; equivalent to 1 - easeQuadIn(1 - t). Also equivalent to easePolyOut.exponent(2).

easeQuadInOut

对称二次缓动;在 t 处于 0–0.5 时使用 easeQuadIn,在 t 处于 0.5–1 时使用 easeQuadOut。也等同于 easePoly.exponent(2)。

🌐 Symmetric quadratic easing; scales easeQuadIn for t in 0–0.5 and easeQuadOut for t in 0.5–1. Also equivalent to easePoly.exponent(2).

easeCubic

Source · easeCubicInOut 的别名。

easeCubicIn

立方缓动;等同于 easePolyIn.指数(3)。

🌐 Cubic easing; equivalent to easePolyIn.exponent(3).

easeCubicOut

反转立方缓动;等同于 1 - easeCubicIn(1 - t)。也等同于 easePolyOut.exponent(3)。

🌐 Reverse cubic easing; equivalent to 1 - easeCubicIn(1 - t). Also equivalent to easePolyOut.exponent(3).

easeCubicInOut

对称立方缓动;对 t 在 0–0.5 的范围使用 easeCubicIn,对 t 在 0.5–1 的范围使用 easeCubicOut。也等同于 easePoly.exponent(3)。

🌐 Symmetric cubic easing; scales easeCubicIn for t in 0–0.5 and easeCubicOut for t in 0.5–1. Also equivalent to easePoly.exponent(3).

easeSin

来源 · easeSinInOut 的别名。

easeSinIn

正弦缓动;返回 sin(t)。

🌐 Sinusoidal easing; returns sin(t).

easeSinOut

反正弦缓动;等同于 1 - easeSinIn(1 - t)。

🌐 Reverse sinusoidal easing; equivalent to 1 - easeSinIn(1 - t).

easeSinInOut

对称正弦缓动;在 t 为 0–0.5 时使用 easeSinIn,在 t 为 0.5–1 时使用 easeSinOut

🌐 Symmetric sinusoidal easing; scales easeSinIn for t in 0–0.5 and easeSinOut for t in 0.5–1.

缓解经验

🌐 easeExp

来源 · easeExpInOut 的别名。

easeExpIn

指数缓动;将 2 提到指数 10 ×(t - 1)。

🌐 Exponential easing; raises 2 to the exponent 10 × (t - 1).

easeExpOut

反指数缓动;等同于 1 - easeExpIn(1 - t)。

🌐 Reverse exponential easing; equivalent to 1 - easeExpIn(1 - t).

指数缓入缓出

🌐 easeExpInOut

对称指数缓动;在 t 为 0–0.5 时使用 easeExpIn 缩放,在 t 为 0.5–1 时使用 easeExpOut

🌐 Symmetric exponential easing; scales easeExpIn for t in 0–0.5 and easeExpOut for t in 0.5–1.

easeCircle

来源 · easeCircleInOut 的别名。

easeCircleIn

Circular 缓和。

🌐 Circular easing.

easeCircleOut

反向圆形缓动;等同于 1 - easeCircleIn(1 - t)。

🌐 Reverse circular easing; equivalent to 1 - easeCircleIn(1 - t).

easeCircleInOut

对称圆形缓动;在 t 为 0–0.5 时使用 easeCircleIn,在 t 为 0.5–1 时使用 easeCircleOut

🌐 Symmetric circular easing; scales easeCircleIn for t in 0–0.5 and easeCircleOut for t in 0.5–1.

easeElastic

来源 · easeElasticOut 的别名。

easeElasticIn

弹性缓动,就像橡皮筋。振荡的振幅周期是可配置的;如果未指定,默认分别为1和0.3。

🌐 Elastic easing, like a rubber band. The amplitude and period of the oscillation are configurable; if not specified, they default to 1 and 0.3, respectively.

easeElasticOut

反向弹性缓动;等同于 1 - elasticIn(1 - t)。

🌐 Reverse elastic easing; equivalent to 1 - elasticIn(1 - t).

easeElasticInOut

对称弹性缓动;对 t 在 0–0.5 范围内使用 elasticIn,在 t 在 0.5–1 范围内使用 elasticOut

🌐 Symmetric elastic easing; scales elasticIn for t in 0–0.5 and elasticOut for t in 0.5–1.

easeElastic.amplitude(a)

返回一个新的弹性缓动,具有指定的振幅 a。振幅 a 必须大于或等于 1。

🌐 Returns a new elastic easing with the specified amplitude a. The amplitude a must be greater than or equal to 1.

easeElastic.period(p)

返回一个具有指定周期 p 的新弹性缓动。

🌐 Returns a new elastic easing with the specified period p.

缓和返回

🌐 easeBack

来源 · easeBackInOut 的别名。

easeBackIn

预期 弹性就像舞者在离地前弯曲膝盖一样。超出 的程度是可配置的;如果未指定,默认值为 1.70158。

easeBackOut

反向先行缓动;等同于 1 - easeBackIn(1 - t)。

🌐 Reverse anticipatory easing; equivalent to 1 - easeBackIn(1 - t).

easeBackInOut

对称的预期缓动;在 t 为 0–0.5 时使用 easeBackIn,在 t 为 0.5–1 时使用 easeBackOut

🌐 Symmetric anticipatory easing; scales easeBackIn for t in 0–0.5 and easeBackOut for t in 0.5–1.

easeBack.overshoot(s)

返回一个具有指定回弹超调 s 的新的后缓动。

🌐 Returns a new back easing with the specified overshoot s.

easeBounce

来源 · easeBounceOut 的别名。

easeBounceIn

像橡皮球一样弹跳缓动。

🌐 Bounce easing, like a rubber ball.

easeBounceOut

反向弹跳缓动;等同于 1 - easeBounceIn(1 - t)。

🌐 Reverse bounce easing; equivalent to 1 - easeBounceIn(1 - t).

easeBounceInOut

对称反弹缓动;在 t 为 0–0.5 时使用 easeBounceIn,在 t 为 0.5–1 时使用 easeBounceOut

🌐 Symmetric bounce easing; scales easeBounceIn for t in 0–0.5 and easeBounceOut for t in 0.5–1.