How AnimBase Works

AnimBase is a lightweight animation engine that interprets structured data in data-anim-init and data-anim-config attributes to drive animations. It supports granular control over values, easing functions, and timelines. Here's a breakdown of its core working principles:


1. StyleConfig

A StyleConfig is a plain JavaScript object that represents inline CSS properties:

{
	"opacity": "0.5",
	"transform": "scale(1.2)"
}

It is represented as a JSON string in data-anim-init.


2. KeyframeConfig

A KeyframeConfig is a mapping of animation keyframes (in frame numbers) to style changes. Each frame references a partial or complete StyleConfig:

{
	"100": {
		"opacity": "1.outQuad"
	},
	"300": {
		"transform": "scale(1.5.outSine)"
	}
}

It is represented as a JSON string in data-anim-config.

Key Principles:


3. Value Parsing and Matching

AnimBase parses each string value using regular expressions to extract individual animatable variables such as:

Each parsed variable is stored along with:

Example:

{
	"boxShadow": "3px 5rem.in 10% #fa2.outBounce"
}

This breaks into:


4. Matching Variables by Position

AnimBase does not track variable names—only position matters.

✅ Correct Example:

<div
	data-anim-init='{ "transform": "translateX(-50%) rotateZ(45deg) scale(1.5)" }'
	data-anim-config='{
		"100": { "transform": "translateX(0%.spring) rotateZ(0deg.outBounce) scale(1)" }
	}'
>
	Text
</div>

Each value maps correctly to its counterpart by position.

❌ Incorrect Example:

<div
	data-anim-init='{ "transform": "translateX(-50%) rotateZ(45deg) scale(1.5)" }'
	data-anim-config='{
		"100": { "transform": "scale(1) translateX(0%.spring) rotateZ(0deg.outBounce)" }
	}'
>
	Text
</div>

The mismatch in value order results in incorrect animations because AnimBase uses the order from data-anim-init as the reference.


5. Non-CSS Awareness

AnimBase does not parse or validate CSS functions. It treats the entire string value as a container of animatable variables, and only those variables are interpolated.

Example:

<div
	data-anim-init='{"color": "rgb(85, 187, 255)"}'
	data-anim-config='{"100": {"color": "rgb(255.outSine, 255, 255)"}}'
>
	Text
</div>

Only the values 85, 187, and 255 are animated, with .outSine applied to the first.


6. Final Notes

You define your timeline and transitions entirely in HTML.

Looking for usage examples? See How to Use AnimBase