Built-in Motion Engine (Beta)
Note: This feature is currently in Beta. While functional, it may undergo changes, and we appreciate any feedback!
This framework includes a lightweight, dependency-free JavaScript motion engine to apply CSS animations to HTML elements.
Enabling the Engine
The Motion Engine is controlled via an environment variable in your .env
file:
USE_ANIMATE
: Set totrue
to enable the engine (default) orfalse
to disable it. When enabled, the necessary JavaScript (public/JS/motion_engine.js
) and CSS (public/css/motion-animations.css
) files are automatically included in your pages.
Example .env
entry:
Using the animate
function
animate
functionThe core of the engine is the animate()
JavaScript function.
Syntax: animate(elementOrSelector, animationName, durationMs)
elementOrSelector
: Can be either an HTMLElement object or a CSS selector string (e.g.,'#myElement'
,'.my-class'
).animationName
: A string representing the name of the animation to apply (e.g.,'fade-in'
). This corresponds to a CSS classmotion-{animationName}
defined inpublic/css/motion-animations.css
.durationMs
: An integer specifying the animation duration in milliseconds (e.g.,300
).
Example Usage:
The function handles adding and removing the necessary CSS classes and setting the animation duration.
Adding New Animations
To add new animations:
Define Keyframes: Open
public/css/motion-animations.css
and define your@keyframes
. It's recommended to prefix them withmotion-
for clarity.Create Animation Class: Add a corresponding CSS class that applies these keyframes.
The base class
.motion-animate
(which includesanimation-fill-mode: forwards;
) will be automatically applied by theanimate
function.Use in JavaScript: You can now use
'slide-up'
as theanimationName
in theanimate
function:
Last updated