Skip to content

Animate Color

Here’s a simple example demonstrating how to animate colors in Animare:

Animate Color
example
import animare from 'animare';
import { lerp, vecToRGB, ease } from 'animare/plugins';
import type { Vec3Array } from 'animare';
const circle = document.querySelector<HTMLDivElement>('.circle');
const fromColor: Vec3Array = [255, 0, 0];
const toColor: Vec3Array = [0, 255, 0];
animare.single({ from: 0, to: 1, duration: 1000, ease: ease.linear }, info => {
if (!circle) return;
const mixed = lerp(fromColor, toColor, info.value);
const rgbString = vecToRGB(mixed);
circle.style.backgroundColor = rgbString;
});