The Animation() constructor of the Web Animations API returns a new Animation object instance.
new Animation()
new Animation(effect)
new Animation(effect, timeline)effect OptionalThe target effect, as an object based on the AnimationEffect interface, to assign to the animation. Although in the future other effects such as SequenceEffects or GroupEffects might be possible, the only kind of effect currently available is KeyframeEffect. This can be null (which is the default) to indicate that there should be no effect applied.
timeline OptionalSpecifies the timeline with which to associate the animation, as an object of a type based on the AnimationTimeline interface. The default value is Document.timeline, but this can be set to null as well.
In the Follow the White Rabbit example, we can use the Animation() constructor to create an Animation for the rabbitDownKeyframes using the document's timeline:
const whiteRabbit = document.getElementById("rabbit");
const rabbitDownKeyframes = new KeyframeEffect(
whiteRabbit,
[{ transform: "translateY(0%)" }, { transform: "translateY(100%)" }],
{ duration: 3000, fill: "forwards" },
);
const rabbitDownAnimation = new Animation(rabbitDownKeyframes);