I added a German Shepherd to my developer portfolio. It roams around the viewport on its own, comes over when you click the page, and runs away from a double-click before going back to exploring. Click the dog itself and it heads to the bottom-left corner, sits for a moment, then falls asleep. It also takes naps on its own.

Getting the dog across the screen was easy. Getting it to look like it was walking took longer. The paws slid when the animation and movement ran at different speeds, and a turn could look like the whole dog flipped in place. On mobile, a dog that settled too close to the first tap could intercept the second one. All three problems came down to how the animation interacted with the page.

One ground line for every pose

I started with a pixel-art prototype and tried an animated SVG in an isolated preview. The version on the portfolio uses transparent WebP sprite sheets drawn on a Canvas. That let me use a side-facing gait for travel and front-facing artwork for sitting and sleeping.

I aligned the artwork to a shared ground line before packing the frames. Each sheet has metadata for its tile size, draw offset, and frame durations. The renderer draws each tile relative to that same ground line, so changing clips keeps the paws planted. Short blends make the switch between side and front views easier to follow. The current frame stays visible while the next sheet decodes.

The resting sequence is stand → sit → lie down → sleep. The transitions play once, and the sleep clip loops until the dog wakes. The same transition sheets play backward to get it on its feet again. I skip the last frame's hold when playing backward so a wake-up starts with movement. Reusing those clips brought the asset set from twelve sheets down to eight.

Moving the feet with the body

I use React to mount a small, labeled button with a canvas inside it. A single requestAnimationFrame loop advances the route, picks the pose, and updates the button's transform. The loop keeps its working state outside React, so moving the dog doesn't rerender the portfolio on every frame.

During free roam, I advance the gait from the distance the dog actually traveled. This is the calculation inside the movement loop, where elapsed is the frame delta in milliseconds.

const strideDistance = Math.max(Math.abs(point.x - current.x), moved * 0.58); walkTime += Math.min(elapsed * 3.7, strideDistance / (sourcePixelsPerMs * spriteScale)); 

I use the horizontal component because the artwork walks in profile. A fraction of the total distance keeps the gait going during mostly vertical parts of a route. Dividing by the calibrated stride speed and the display scale converts screen distance to animation time. Now, when the dog slows down at the end of a route, its feet slow down with it.

For roaming, I sample destinations inside the viewport and favor curved routes that carry the current heading through the next leg. The route planner measures interactive controls and expands their bounds by the dog's footprint. That gives it room to turn and detour without running across a button a visitor is trying to click.

A tap should still feel like a tap

A single click and a double-click start with the same event. I give the first click a 320 ms window. A nearby second click cancels the pending approach and sends the dog away from the pointer first. On touchscreens I also track pointer taps, filter out drags and long presses, and ignore the synthetic click that can follow a tap.

The touch-specific detail that mattered most was where the dog stopped. I gave it extra clearance around the tap position so the dog button wouldn't catch a second tap intended for the page. Clicking the dog itself has a separate handler, which sends it to its corner and starts the sit-to-sleep sequence.

Fast scrolling and browser history changes also send the dog into a resting pose. The route planner waits for the layout to settle before measuring controls again. Keyboard users can activate the mascot through its native button, and people who prefer reduced motion get the destination and pose without the travel animation.

Checking the cleanup against the original behavior

Once the gestures felt right, I wanted to simplify the code without changing those interactions again. I replayed the same seeded sequence of clicks, taps, fast scrolls, and visibility changes against both versions. Across desktop, touch, and reduced-motion simulations, all 9,300 recorded frames matched on position, mode, pose, motion, and visibility. I also checked gestures and fast scrolling in headless Chrome.

The regression trace gave me a way to keep the details that made the dog feel alive while cutting duplicate asset files and code. In the finished feature, one loop connects where the dog is going, what its feet should be doing, and when it should settle down.