d3-ease
示例 · 缓动是一种扭曲时间以控制动画中表观运动的方法。它最常用于 慢进慢出。通过减少时间,动画过渡 更加平滑,并表现出更合理的运动。
¥Examples · Easing is a method of distorting time to control apparent motion in animation. It is most commonly used for slow-in, slow-out. By easing time, animated transitions are smoother and exhibit more plausible motion.
此模块中的缓动类型实现了 缓动方法 函数,它接受标准化时间 t 并返回相应的“缓动”时间 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 tʹ. 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.
ease(t) {#_ease}
给定指定的归一化时间 t,通常在 [0,1] 范围内,返回“缓和”时间 tʹ,该时间通常在 [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 tʹ, 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:
const te = d3.easeCubic(t);
要应用自定义 elastic 缓动函数,请在动画开始前创建缓动函数:
¥To apply custom elastic easing, create your easing function before the animation starts:
const ease = d3.easeElastic.period(0.4);
然后在动画期间,应用缓动函数:
¥Then during the animation, apply the easing function:
const te = ease(t);
另请参阅 transition.ease。
¥See also transition.ease.
easeLinear
源代码 · 线性缓动;恒等函数;linear(t) 返回 t。
¥Source · Linear easing; the identity function; linear(t) returns t.
easePoly
源代码 · easePolyInOut 的别名。
¥Source · Alias for easePolyInOut.
easePolyIn
多项式缓动;将 t 的指数 exponent 进行求值。如果未指定指数,则默认为 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
对称多项式缓动;将 easePolyIn 的 t 缩放到 0-0.5 之间,将 easePolyOut 的 t 缩放到 0.5-1 之间。如果未指定指数,则默认为 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) {#easePoly_exponent}
返回一个具有指定指数 e 的新多项式缓动函数。例如,要创建 easeLinear、easeQuad 和 easeCubic 的等效项:
¥Returns a new polynomial easing with the specified exponent e. For example, to create equivalents of easeLinear, easeQuad, and easeCubic:
const linear = d3.easePoly.exponent(1);
const quad = d3.easePoly.exponent(2);
const cubic = d3.easePoly.exponent(3);
easeQuad
源代码 · easeQuadInOut 的别名。
¥Source · Alias for easeQuadInOut.
easeQuadIn
二次缓动;相当于 easePolyIn.exponent(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
对称二次缓动;将 easeQuadIn 的 t 缩放到 0-0.5 之间,将 easeQuadOut 的 t 缩放到 0.5-1 之间。也等同于 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
源代码 · easeCubicInOut 的别名。
¥Source · Alias for easeCubicInOut.
easeCubicIn
三次缓和;相当于 easePolyIn.exponent(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
对称三次缓动;将 easeCubicIn 的 t 缩放到 0-0.5 之间,将 easeCubicOut 的 t 缩放到 0.5-1 之间。也等同于 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 的别名。
¥Source · Alias for easeSinInOut.
easeSinIn
正弦缓和;返回 sin(t)。
¥Sinusoidal easing; returns sin(t).
easeSinOut
反向正弦缓动;相当于 1 - easeSinIn(1 - t)。
¥Reverse sinusoidal easing; equivalent to 1 - easeSinIn(1 - t).
easeSinInOut
对称正弦缓动;将 easeSinIn 的 t 缩放到 0-0.5 之间,将 easeSinOut 的 t 缩放到 0.5-1 之间。
¥Symmetric sinusoidal easing; scales easeSinIn for t in 0–0.5 and easeSinOut for t in 0.5–1.
easeExp
源代码 · easeExpInOut 的别名。
¥Source · Alias for 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
对称指数缓动;将 easeExpIn 的 t 缩放到 0-0.5 之间,将 easeExpOut 的 t 缩放到 0.5-1 之间。
¥Symmetric exponential easing; scales easeExpIn for t in 0–0.5 and easeExpOut for t in 0.5–1.
easeCircle
源代码 · easeCircleInOut 的别名。
¥Source · Alias for easeCircleInOut.
easeCircleIn
Circular 缓和。
¥Circular easing.
easeCircleOut
反向循环缓动;相当于 1 - easeCircleIn(1 - t)。
¥Reverse circular easing; equivalent to 1 - easeCircleIn(1 - t).
easeCircleInOut
对称循环缓动;将 easeCircleIn 的 t 缩放到 0-0.5 之间,将 easeCircleOut 的 t 缩放到 0.5-1 之间。
¥Symmetric circular easing; scales easeCircleIn for t in 0–0.5 and easeCircleOut for t in 0.5–1.
easeElastic
源代码 · easeElasticOut 的别名。
¥Source · Alias for easeElasticOut.
easeElasticIn
弹性缓动,像橡皮筋一样。振荡的 amplitude 和 period 是可配置的;如果未指定,则默认分别为 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
对称弹性缓动;将 elasticIn 的 t 缩放到 0-0.5 之间,将 elasticOut 的 t 缩放到 0.5-1 之间。
¥Symmetric elastic easing; scales elasticIn for t in 0–0.5 and elasticOut for t in 0.5–1.
easeElastic.amplitude(a) {#easeElastic_amplitude}
返回一个具有指定振幅 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) {#easeElastic_period}
返回一个具有指定周期 p 的新弹性缓动函数。
¥Returns a new elastic easing with the specified period p.
easeBack
源代码 · easeBackInOut 的别名。
¥Source · Alias for easeBackInOut.
easeBackIn
预期 就像舞者在跳下地板前弯曲膝盖一样舒缓。overshoot 的度数是可配置的;如果未指定,则默认为 1.70158。
¥Anticipatory easing like a dancer bending her knees before jumping off the floor. The degree of overshoot is configurable; if not specified, it defaults to 1.70158.
easeBackOut
反向预期缓动;相当于 1 - easeBackIn(1 - t)。
¥Reverse anticipatory easing; equivalent to 1 - easeBackIn(1 - t).
easeBackInOut
对称预期缓动;将 easeBackIn 的 t 缩放到 0-0.5 之间,将 easeBackOut 的 t 缩放到 0.5-1 之间。
¥Symmetric anticipatory easing; scales easeBackIn for t in 0–0.5 and easeBackOut for t in 0.5–1.
easeBack.overshoot(s) {#easeBack_overshoot}
返回一个具有指定过冲 s 的新后退缓动函数。
¥Returns a new back easing with the specified overshoot s.
easeBounce
源代码 · easeBounceOut 的别名。
¥Source · Alias for easeBounceOut.
easeBounceIn
像橡皮球一样弹跳缓动。
¥Bounce easing, like a rubber ball.
easeBounceOut
反向弹跳缓动;相当于 1 - easeBounceIn(1 - t)。
¥Reverse bounce easing; equivalent to 1 - easeBounceIn(1 - t).
easeBounceInOut
对称反弹缓动;将 easeBounceIn 的 t 缩放到 0-0.5 之间,将 easeBounceOut 的 t 缩放到 0.5-1 之间。
¥Symmetric bounce easing; scales easeBounceIn for t in 0–0.5 and easeBounceOut for t in 0.5–1.