--- title: EffectTiming.easing slug: Web/API/EffectTiming/easing translation_of: Web/API/EffectTiming/easing ---
这个{{domxref("EffectTiming")}} 词的 easing 属性在 Web Animations API 指定用于缩放时间以产生缓和效果的计时函数,easing 是动画随时间变化的速率。
{{domxref("Element.animate()")}}, {{domxref("KeyframeEffectReadOnly.KeyframeEffectReadOnly", "KeyframeEffectReadOnly()")}}, and {{domxref("KeyframeEffect.KeyframeEffect", "KeyframeEffect()")}} all accept an object of timing properties including easing. The value of easing corresponds directly to {{domxref("AnimationEffectTimingReadOnly.easing")}} in {{domxref("AnimationEffectReadOnly.timing", "timing")}} objects returned by {{domxref("AnimationEffectReadOnly")}}, {{domxref("KeyframeEffectReadOnly")}}, and {{domxref("KeyframeEffect")}}.
var timingProperties = {
easing: {{cssxref("single-transition-timing-function")}}
}
timingProperties.easing = {{cssxref("single-transition-timing-function")}}
A string defining the timing function to use for easing transitions during the animation process. Accepts several pre-defined {{domxref("DOMString")}} values, a steps() timing function like steps(5, end), or a custom cubic-bezier value like cubic-bezier(0.42, 0, 0.58, 1). Defaults to linear. Available values include:
linearcubic-bezier(<number>, <number>, <number>, <number>)easecubic-bezier(0.25, 0.1, 0.25, 1).ease-incubic-bezier(0.42, 0, 1, 1).ease-outcubic-bezier(0, 0, 0.58, 1).ease-in-outcubic-bezier(0.42, 0, 0.58, 1).frames(<integer>)steps() and frames().steps(<integer>[, [ start | end ] ]?)step-startsteps(1, start)step-endsteps(1, end).In the Red Queen's Race example, we animate Alice and the Red Queen by passing an easing of steps(7, end) to animate():
// Define the key frames
var spriteFrames = [
{ transform: 'translateY(0)' },
{ transform: 'translateY(-100%)' }
];
// Get the element that represents Alice and the Red Queen
var redQueen_alice_sprite = document.getElementById('red-queen_and_alice_sprite');
// Animate Alice and the Red Queen using steps()
var redQueen_alice = redQueen_alice_sprite.animate(
spriteFrames, {
easing: 'steps(7, end)',
direction: "reverse",
duration: 600,
playbackRate: 1,
iterations: Infinity
});
| Specification | Status | Comment |
|---|---|---|
| {{SpecName('Web Animations', '#time-transformations', 'easing' )}} | {{Spec2('Web Animations')}} | Editor's draft. |
{{Compat("api.EffectTiming.easing", 2)}}
animation-timing-function and transition-timing-function.