All technologies

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.

SVG / POINTER / SPRING01—04

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.

JELLY MOTION TELEMETRYREAL TIME
Pointer speed0.00PX / MS
Deformation force0PERCENT
Motion angle0°VECTOR

Telemetry for training: all calculations are performed locally in the browser, the data is not sent anywhere.

BEHAVIOUR / 02

How animation reacts to movement

  1. Reading movement

    01

    Pointer Events give current coordinates. The difference between adjacent events turns into a vector and velocity.

  2. Determining direction

    02

    Angle is calculated using atan2. The shortest turn is smoothed out in a split second, without jumps through 360°.

  3. Catching up with the cursor

    03

    Position lives like a spring: attraction to the target creates inertia, damping dampens unnecessary vibrations.

  4. Changing the shape

    04

    Speed 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.

motion.jsrequestAnimationFrame
velocity += (target - position) × spring
velocity ×= damping
position += velocity × deltaTime

energy = clamp(pointerSpeed / maxSpeed, 0, 1)
rotation += shortestAngle × response

IMPLEMENTATION / 04

Technologies and implementation

  1. Vector anatomy

    SVG

    The dome, highlight, edge and six tentacles are separate SVG paths. They remain sharp on any screen and can warp independently.

  2. Parametric keyframes

    CSS

    JavaScript communicates gesture strength via CSS custom properties. Keyframes alone provide hundreds of intermediate states without generating new styles.

  3. Pointer Events and Physics

    JS

    Speed is calculated in px/ms, taking into account the time between events. The spring is updated in requestAnimationFrame and normalizes the frame pitch.

  4. Single compact layer

    DOM

    The 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

  1. Frame rate independent

    deltaTime is limited and participates in all calculations. Motion remains consistent at 60Hz and on high refresh rate displays.

  2. 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.

  3. 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.

  4. 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

pointermove→vector + speed→spring solver→CSS variables→SVG transform

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.

Discuss interactive project