element.animate(
[
{
// from
opacity: 0,
color: "white",
},
{
// to
opacity: 1,
color: "black",
},
],
2000,
);Keyframe Formats / notebook
Keyframe Formats
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
element.animate(
[{ opacity: 1 }, { opacity: 0.1, offset: 0.7 }, { opacity: 0 }],
2000,
); element.animate(
[
{ opacity: 1, easing: "ease-out" },
{ opacity: 0.1, easing: "ease-in" },
{ opacity: 0 },
],
2000,
); element.animate(
{
opacity: [0, 1], // [ from, to ]
color: ["white", "black"], // [ from, to ]
},
2000,
); element.animate(
{
opacity: [0, 1], // offset: 0, 1
backgroundColor: ["red", "yellow", "green"], // offset: 0, 0.5, 1
},
2000,
); element.animate(
{
opacity: [0, 0.9, 1],
offset: [0, 0.8], // Shorthand for [ 0, 0.8, 1 ]
easing: ["ease-in", "ease-out"],
},
2000,
);// Animate from the current state to translateX(300px)
logo.animate({ transform: "translateX(300px)" }, 1000);
// Animate from translateX(300px) to the current state
logo.animate({ transform: "translateX(300px)", offset: 0 }, 1000);
// Animate from the current state to translateX(300px) and back to the current state
logo.animate({ transform: "translateX(300px)", offset: 0.5 }, 1000);