SCRIPTS · MOTION SYSTEM
Interactive animation in JavaScript
The interactive cursor turns mouse movement into character: it gently follows the pointer, turns in the direction of the gesture and changes the stroke force from barely noticeable to maximum.
LIVE / 01
Try Animation Controls
Slow movement hardly distorts the silhouette. A quick gesture compresses the dome, extends the tentacles, and adds momentum. The direction is determined separately from the force - so the jellyfish does not fly sideways.
Telemetry for training: all calculations are performed locally in the browser, the data is not sent anywhere.
BEHAVIOUR / 02
How animation reacts to movement
Reading movement
01Pointer Events give current coordinates. The difference between adjacent events turns into a vector and velocity.
Determining direction
02Angle is calculated using atan2. The shortest turn is smoothed out in a split second, without jumps through 360°.
Catching up with the cursor
03Position lives like a spring: attraction to the target creates inertia, damping dampens unnecessary vibrations.
Changing the shape
04Speed is normalized to a factor of 0…1. It controls the compression of the dome, the length of the tentacles and the strength of the impulse.
MODEL / 03
Motion model
Each frame recalculates speed and position. Thanks to this, the jellyfish is not glued to the cursor, but has its own mass and continues to move gently after the mouse stops.
velocity += (target - position) × spring
velocity ×= damping
position += velocity × deltaTime
energy = clamp(pointerSpeed / maxSpeed, 0, 1)
rotation += shortestAngle × responseIMPLEMENTATION / 04
Technologies and implementation
Vector anatomy
SVGThe dome, highlight, edge and six tentacles are separate SVG paths. They remain sharp on any screen and can warp independently.
Parametric keyframes
CSSJavaScript communicates gesture strength via CSS custom properties. Keyframes alone provide hundreds of intermediate states without generating new styles.
Pointer Events and Physics
JSSpeed is calculated in px/ms, taking into account the time between events. The spring is updated in requestAnimationFrame and normalizes the frame pitch.
Single compact layer
DOMThe effect creates a single container with inline SVG. pointer-events are disabled so the jellyfish doesn't interfere with links, buttons, or text selection.
DETAILS / 05
Animation Performance
Frame rate independent
deltaTime is limited and participates in all calculations. Motion remains consistent at 60Hz and on high refresh rate displays.
Two rotation modes
During a gesture, the direction is caught up quickly - in about 0.1–0.2 seconds. After stopping, a slow stabilization remains to eliminate flickering.
Peak stroke energy
Within one phase, the maximum measured speed is maintained. Therefore the form does not jitter due to unequal spacing between mouse events.
Respect user settings
The cursor is not created on touch devices. With prefers-reduced-motion, interactive motion is disabled, but the page content remains accessible.
PIPELINE / 06
From event to pixel
No images, Canvas or third-party animation libraries: just browser APIs, CSS and vector graphics.
BIG FISH / INTERACTION DESIGN
Let's discuss an interactive project
We use mechanics like this where they support the idea of the interface rather than distract from it.