Custom keyframes for scroll animations
The from option gives the most common entrances. For full control, give native Web Animations keyframes in the keyframes option. The keyframes replace the generated entrance.
Give native keyframes
Section titled “Give native keyframes”Set keyframes to an array of keyframe objects. This entrance zooms in and bounces a little at the end:
Your device asks for reduced motion, so the content shows with no animation.
import { Reveal } from "@awesome-reveal/react";
const bounceIn = [ { opacity: 0, scale: 0.8, easing: "cubic-bezier(0.34, 1.56, 0.64, 1)" }, { opacity: 1, scale: 1 },];
export function BouncingLogo() { return ( <Reveal keyframes={bounceIn}> <img src="/logo.svg" alt="Awesome Reveal" /> </Reveal> );}import { Reveal } from "@awesome-reveal/react";
const bounceIn = [ { opacity: 0, scale: 0.8, easing: "ease-out" }, { opacity: 1, scale: 1 },];
export function BouncingLogo() { return ( <Reveal keyframes={bounceIn}> <img src="/logo.svg" alt="Awesome Reveal" /> </Reveal> );}import { Reveal } from "@awesome-reveal/react";
const bounceIn = [ { opacity: 0, scale: 0.8, easing: "linear" }, { opacity: 1, scale: 1 },];
export function BouncingLogo() { return ( <Reveal keyframes={bounceIn}> <img src="/logo.svg" alt="Awesome Reveal" /> </Reveal> );}<script setup>import { Reveal } from "@awesome-reveal/vue";
const bounceIn = [ { opacity: 0, scale: 0.8, easing: "cubic-bezier(0.34, 1.56, 0.64, 1)" }, { opacity: 1, scale: 1 },];</script>
<template> <Reveal :keyframes="bounceIn"> <img src="/logo.svg" alt="Awesome Reveal" /> </Reveal></template><script setup>import { Reveal } from "@awesome-reveal/vue";
const bounceIn = [ { opacity: 0, scale: 0.8, easing: "ease-out" }, { opacity: 1, scale: 1 },];</script>
<template> <Reveal :keyframes="bounceIn"> <img src="/logo.svg" alt="Awesome Reveal" /> </Reveal></template><script setup>import { Reveal } from "@awesome-reveal/vue";
const bounceIn = [ { opacity: 0, scale: 0.8, easing: "linear" }, { opacity: 1, scale: 1 },];</script>
<template> <Reveal :keyframes="bounceIn"> <img src="/logo.svg" alt="Awesome Reveal" /> </Reveal></template>---import { Reveal } from "@awesome-reveal/astro";
const bounceIn = [ { opacity: 0, scale: 0.8, easing: "cubic-bezier(0.34, 1.56, 0.64, 1)" }, { opacity: 1, scale: 1 },];---
<Reveal keyframes={bounceIn}> <img src="/logo.svg" alt="Awesome Reveal" /></Reveal>---import { Reveal } from "@awesome-reveal/astro";
const bounceIn = [ { opacity: 0, scale: 0.8, easing: "ease-out" }, { opacity: 1, scale: 1 },];---
<Reveal keyframes={bounceIn}> <img src="/logo.svg" alt="Awesome Reveal" /></Reveal>---import { Reveal } from "@awesome-reveal/astro";
const bounceIn = [ { opacity: 0, scale: 0.8, easing: "linear" }, { opacity: 1, scale: 1 },];---
<Reveal keyframes={bounceIn}> <img src="/logo.svg" alt="Awesome Reveal" /></Reveal>import { reveal } from "@awesome-reveal/core";
reveal(".logo", { keyframes: [ { opacity: 0, scale: 0.8, easing: "cubic-bezier(0.34, 1.56, 0.64, 1)" }, { opacity: 1, scale: 1 }, ],});import { reveal } from "@awesome-reveal/core";
reveal(".logo", { keyframes: [ { opacity: 0, scale: 0.8, easing: "ease-out" }, { opacity: 1, scale: 1 }, ],});import { reveal } from "@awesome-reveal/core";
reveal(".logo", { keyframes: [ { opacity: 0, scale: 0.8, easing: "linear" }, { opacity: 1, scale: 1 }, ],});You cannot use from and keyframes together. TypeScript rejects the two options on the same element.
Set the easing
Section titled “Set the easing”Set the easing in the keyframes. The easing of a keyframe applies from that keyframe to the next keyframe. Without an easing, the change from a keyframe to the next keyframe is linear. No option sets the easing of the full entrance.
The easing takes a CSS easing function:
- A keyword, such as
ease-outorease-in-out. - A
cubic-bezier()curve. A second or fourth number above 1 makes the element go past its end position and come back. - A
linear()function. It connects a list of points, so it can make a spring or a bounce. The positions inlinear()are fractions of theduration. Set a longerdurationfor a spring with more bounces. It needs Chrome 113, Firefox 112 or Safari 17.2. In other browsers, the element shows with no animation.
This example zooms three cards at the same time: with ease-out, with a cubic-bezier() overshoot and with a linear() spring. The curve under each card shows the progress of the entrance over time. The dashed line is the end size. The code shows the linear() spring:
ease-out overshoot spring
Your device asks for reduced motion, so the content shows with no animation.
import { Reveal } from "@awesome-reveal/react";
const spring = "linear(0, 0.62, 1.01, 1.12, 1.09, 1.03, 1 60%, 1)";
const springIn = [ { opacity: 0, scale: 0.4, easing: spring }, { opacity: 1, scale: 1 },];
export function SpringCard() { return ( <Reveal className="card" keyframes={springIn} duration={1000}> A card </Reveal> );}<script setup>import { Reveal } from "@awesome-reveal/vue";
const spring = "linear(0, 0.62, 1.01, 1.12, 1.09, 1.03, 1 60%, 1)";
const springIn = [ { opacity: 0, scale: 0.4, easing: spring }, { opacity: 1, scale: 1 },];</script>
<template> <Reveal class="card" :keyframes="springIn" :duration="1000">A card</Reveal></template>---import { Reveal } from "@awesome-reveal/astro";
const spring = "linear(0, 0.62, 1.01, 1.12, 1.09, 1.03, 1 60%, 1)";
const springIn = [ { opacity: 0, scale: 0.4, easing: spring }, { opacity: 1, scale: 1 },];---
<Reveal class="card" keyframes={springIn} duration={1000}> A card</Reveal>import { reveal } from "@awesome-reveal/core";
const spring = "linear(0, 0.62, 1.01, 1.12, 1.09, 1.03, 1 60%, 1)";
reveal(".card", { keyframes: [ { opacity: 0, scale: 0.4, easing: spring }, { opacity: 1, scale: 1 }, ], duration: 1000,});End at the resting style
Section titled “End at the resting style”The entrance does not keep its last keyframe after it ends. The element then returns to its own style. If the last keyframe is different from that style, the element jumps at the end of the entrance. Make the last keyframe agree with the resting style of the element.
Keep the element’s own values
Section titled “Keep the element’s own values”While the entrance plays, the keyframes replace the element’s own values of the properties that they animate. In the JavaScript API, they also replace them while the element waits. To end at the element’s own value, end with a neutral additive keyframe. For example, this entrance ends at the opacity of the element, also when the CSS sets opacity: 0.8:
const keyframes = [{ opacity: 0 }, { opacity: 0, composite: "add" }];An additive keyframe adds its value to the element’s own value. An opacity of 0 adds nothing.
- A keyframe with
compositeneeds Firefox 80 or Safari 16. - Chromium runs an animation with an additive keyframe on the main thread. The animation can stutter when the main thread is busy.
Give explicit values to the first keyframe
Section titled “Give explicit values to the first keyframe”Set each animated property in the first keyframe. An open WebKit bug (212409) can take an implicit start value from an earlier animation.
Animate custom properties
Section titled “Animate custom properties”A keyframe can animate a CSS custom property, such as "--progress". Register the property with @property and give it a syntax, such as "<number>". Without a registration, the browser cannot interpolate the value, so the value changes in one step at the middle of the entrance.
Animate the properties that the compositor runs
Section titled “Animate the properties that the compositor runs”Animate opacity, transform, translate, scale and rotate when possible. The browser runs these animations on the compositor, so a busy main thread does not make them stutter. A layout property, such as width, top or margin, causes a layout and a paint on each frame.