Recreating Web Animations: From Visual Fidelity to Interaction Fidelity
Recreating a web animation is far harder than recreating a static page. Instead of matching pixels, you have to reproduce continuous states along a timeline: particle systems, scroll-driven transformations, and mouse-driven feedback. This article breaks down four practical recreation paths, from recovering source code and analyzing screenshot sequences to building a Canvas particle system from scratch or using declarative animation with a unified clock. It also covers three common failure points—inconsistent easing curves, coarse scroll progress mapping, and missing state machines—along with a practical methodology for AI-assisted recreation, plus performance, accessibility, and maintainability guidance for production.
1. Problem Definition: Why Recreating Animation Is Harder Than Recreating a Page
In web development, “high-fidelity reproduction of a page” is usually understood as reproducing static visuals: layout, colors, typography, and spacing. But when the target page includes hero-screen particle effects, scroll-driven morphing, and mouse interaction feedback, the nature of the problem changes fundamentally—you are no longer reproducing “pixels,” but “continuous states along a timeline.”
Take the requirement that “the hero particle system disperses and gathers on scroll, and finally forms a specific shape” as an example. It involves at least the following sub-problems:
- Mathematical modeling of the particle system: each particle’s initial position, target position, and motion curve;
- Mapping from scroll progress to animation state: how to map
scrollYto a normalized progress value between 0 and 1, then map it to particle interpolation parameters; - Physical feedback for mouse interaction: how to calculate the repulsion/attraction field applied to particles near the cursor;
- Visual continuity across multiple forms: scattered state (star points) → intermediate state → gathered state (logo), with no abrupt “jumps” between forms;
- Rendering performance: dozens or even hundreds of particles animating continuously at 60fps without dropping frames.
This is also the core reason why the three candidate solutions diverged in the original evaluation scenario: static screenshot analysis can reproduce “what it looks like,” but struggles to reproduce “how it moves.” A true recreation requires reverse-engineering the animation’s timing functions from source code or behavioral observation.
2. Breaking Down the Technical Approach: Four Mainstream Recreation Paths
When facing the requirement to “recreate the animation of a live page,” there are typically four engineering paths, each with its own applicable boundaries.
2.1 Path One: Directly Obtain and Restore the Source Code
The ideal scenario is when the target page’s animation is driven by readable source code (e.g., unobfuscated JS/CSS). In this case, you can use browser developer tools to:
- Locate the DOM node where the animation is mounted in the
Elementspanel (usually a<canvas>or a<div>container); - Find animation-related script files in the
Sourcespanel; - Observe whether any chunks are loaded separately in the
Networkpanel.
Key decision point: if the scripts are minified and obfuscated (variable names replaced with a, b, e1), the cost of direct restoration rises sharply. A more realistic approach in this case is behavioral reproduction—observe the input/output relationship of the animation and rewrite the implementation yourself.
2.2 Path Two: Behavioral Analysis Based on Screenshot Sequences
When source code cannot be read directly, you can collect a set of keyframes by “scrolling + taking screenshots”:
Capture strategy:- Scroll progress 0% → Screenshot A (scattered state)- Scroll progress 25% → Screenshot B- Scroll progress 50% → Screenshot C (intermediate state)- Scroll progress 75% → Screenshot D- Scroll progress 100% → Screenshot E (gathered state / logo state)
Analyzing the screenshot sequence lets you extract: particle count, colors, size distribution, and outline features of the final form. You can then reimplement with a generic particle system—not aiming for code parity, only for visual parity.
2.3 Path Three: Implementing a Canvas Particle System from Scratch
This is the most commonly used engineering path. The core idea is to represent both the “gathered shape” and the “scattered star points” as sets of particle coordinates, and achieve morphing through interpolation.
A minimal runnable implementation skeleton:
class ParticleField {constructor(canvas, options = {}) {this.canvas = canvas;this.ctx = canvas.getContext('2d');this.count = options.count ?? 800;this.progress = 0; // scroll progress 0~1this.mouse = { x: -9999, y: -9999 };this.particles = [];this._init();}_init() {const { width, height } = this.canvas;for (let i = 0; i < this.count; i++) {this.particles.push({// Scattered state: random star pointssx: Math.random() * width,sy: Math.random() * height,// Gathered state: sample points on the target shapetx: 0, ty: 0,x: 0, y: 0,size: Math.random() * 1.8 + 0.4,phase: Math.random() * Math.PI * 2});}this._assignTargets();}// Map gathered-state target coordinates sampled from an offscreen shape to particles_assignTargets() {const off = document.createElement('canvas');const octx = off.getContext('2d');// Assume drawLogo(octx) draws the target shape onto the offscreen canvasdrawLogo(octx);const { data, width, height } = octx.getImageData(0, 0, off.width, off.height);const pts = [];for (let y = 0; y < height; y += 4) {for (let x = 0; x < width; x += 4) {if (data[(y * width + x) * 4 + 3] > 128) {pts.push({ x, y });}}}this.particles.forEach((p, i) => {const t = pts[i % pts.length];p.tx = t.x;p.ty = t.y;});}render() {const { ctx, canvas, progress, mouse } = this;ctx.clearRect(0, 0, canvas.width, canvas.height);// Easing: make the interpolation feel more naturalconst t = this._easeInOutCubic(progress);for (const p of this.particles) {// Base interpolation: scattered state → gathered statelet x = p.sx + (p.tx - p.sx) * t;let y = p.sy + (p.ty - p.sy) * t;// Mouse repulsion fieldconst dx = x - mouse.x;const dy = y - mouse.y;const dist = Math.hypot(dx, dy);const radius = 120;if (dist < radius && dist > 0.01) {const force = (radius - dist) / radius * 14;x += (dx / dist) * force;y += (dy / dist) * force;}// Subtle breathing motion to avoid complete stillnessy += Math.sin(t * Math.PI * 2 + p.phase) * 0.6;ctx.beginPath();ctx.arc(x, y, p.size, 0, Math.PI * 2);ctx.fillStyle = `rgba(255,255,255,${0.85 - t * 0.3})`;ctx.fill();}}_easeInOutCubic(t) {return t < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2;}}
Key design points in this code:
- Scattered-state coordinates
(sx, sy)and gathered-state coordinates(tx, ty)are stored separately and interpolated by progress at render time, naturally supporting any intermediate state; - Offscreen canvas sampling converts a logo shape into particle coordinates, eliminating the need to manually annotate hundreds of target points;
- Easing functions make the interpolation non-linear, making it look more like being “attracted” rather than “teleported.”
2.4 Path Four: Declarative Implementation Based on Mature Animation Capabilities
In addition to the imperative Canvas approach above, you can also leverage declarative animation capabilities (such as generic web animation APIs) or lightweight animation libraries. Their advantages are small code size and convenient timeline management; their weakness is weaker expressiveness for per-particle logic such as “particle-level mouse interaction,” so mixed usage is often required.
A typical pattern:
// Drive a unified clock with requestAnimationFrame to avoid multiple animation sources acting independentlyconst clock = {last: 0,start: 0,duration: 1200,get progress() {const now = performance.now();if (!this.start) this.start = now;return Math.min(1, (now - this.start) / this.duration);}};function loop() {particleField.progress = clock.progress;particleField.render();if (clock.progress < 1) requestAnimationFrame(loop);}requestAnimationFrame(loop);
A unified clock is key to coordinating multiple animations: particle gathering/dispersing, background gradients, and text reveals should all be driven by the same progress; otherwise, animations will fall out of rhythm with each other.
3. Three Common Pitfalls in Interaction Reproduction
In the original evaluation scenario, candidate solutions generally “ran on the first version, but had obvious differences in form and motion.” The differences usually appear in the following three places.
3.1 Inconsistent Easing Curves
Linear interpolation is the easiest to write and also the easiest to “look wrong.” Real animations almost always use easing. Common choices:
| Easing Type | Visual Feel | Use Case |
|---|---|---|
| linear | Mechanical, constant speed | Progress bars, looping scrolls |
| ease-out | Fast start, slow finish | Element entrance, gathering finish |
| ease-in-out | Slow at both ends, fast in the middle | Morphing, breathing feel |
| Elastic/Bounce | Has overshoot | Emphasis, playful interactions |
When recreating, if you are unsure which curve the original site uses, you can reverse-engineer it by sampling displacement across multiple frames: measure the displacement ratio of intermediate frames between two keyframes—if the middle frame has completed about 50% of the displacement, it is close to linear; if it has completed 70%+, it leans toward ease-out.
3.2 Coarse Scroll Progress Mapping
Many implementations directly use scrollY / maxScroll, but the animation interval on the target page often occupies only part of the entire page scroll. The correct approach is to limit the interval:
function mapScrollProgress(scrollY, start, end) {const raw = (scrollY - start) / (end - start);return Math.max(0, Math.min(1, raw)); // clamp to 0~1}// Example: the animation completes only within the 0 ~ 800px scroll rangeconst p = mapScrollProgress(window.scrollY, 0, 800);
Failing to limit the interval causes the animation to “finish early” or “never finish,” a common source of visual discrepancy.
3.3 Missing State Machine, Abrupt Form Switching
“Gathering from scattered” is not a single interpolation, but includes multiple visual states. It is recommended to model them explicitly:
State machine design:STATE_SCATTERED (0.0 ~ 0.35) Star points drift slowly, spacing shrinksSTATE_TRANSITION (0.35 ~ 0.75) Main interpolation phase, particles converge to target coordinatesSTATE_ASSEMBLED (0.75 ~ 1.0) Gathered, with breathing/glow/micro-rotation layered on top
Each state can have its own additional effects (e.g., adding a glow layer after gathering completes), making the visual hierarchy much richer than “a single interpolation all the way through.”
4. A Practical Methodology for AI-Assisted Recreation
The original evaluation scenario was essentially a practice of “reverse-engineering a recreation using intelligent coding tools.” From it, we can distill a more reliable way of collaborating, rather than simply dumping requirements on a model.
4.1 Prompts Should Include “Acceptance Criteria”
Vague requirements (“make a really cool effect”) inevitably lead to vague output. An effective prompt should include at least:
- Target definition: a specific URL or specific target component, not “something similar”;
- Method authorization: permission to use browser automation, screenshot analysis, source code reading, and any other means;
- Verifiable acceptance points: e.g., “complete gathering from scroll 0→800px,” “the outline after gathering is within an acceptable error range compared to the original site,” “particles noticeably avoid the cursor when it approaches”;
- Delivery format: constraints such as a standalone runnable page, single-file HTML, no external dependencies.
4.2 Iterate Rather Than Generate in One Shot
Complex animations can almost never be generated correctly in one shot. A reasonable rhythm is:
- Round one: confirm the technical approach and overall structure (whether to use Canvas, whether to split states);
- Round two: confirm the static form (whether the outline after gathering is correct);
- Round three: confirm the motion rhythm (easing, time intervals);
- Round four: confirm interaction details (mouse repulsion strength, action radius).
Each round makes incremental corrections based on a runnable artifact, rather than regenerating from scratch.
4.3 Use Screenshot Comparison for Objective Regression
A human’s “looks about the same at a glance” is unreliable. It is recommended to set up a comparison process: at the same scroll progress and the same mouse position, take a screenshot of both the old and new implementations, and do a pixel-level or outline-level comparison. This turns “doesn’t feel right” into locatable, concrete differences (position offset? density difference? wrong colors?).
5. Performance and Engineering Wrap-up
After the recreation is complete, there are still several engineering wrap-up tasks that determine final quality.
Rendering Optimization
- When the particle count exceeds about 1500, per-particle
beginPath/arc/fillon 2D Canvas becomes a bottleneck; considerWebGL(such as a generic GPU point-sprite approach) or writing pixels directly viaImageData; - Layer static elements (background, copy) and dynamic elements (particles) separately to avoid repainting the entire page;
- Use
IntersectionObserverto pauserequestAnimationFramewhen the animation area is not visible, saving resources.
Adaptation and Degradation
const reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;if (reduceMotion) {// Render the final gathered state directly, without animationparticleField.progress = 1;particleField.render();}
You must respect the system’s “reduce motion” preference; at the same time, reduce particle count and frame rate cap on small screens or low-performance devices.
Maintainability
Split “shape definitions,” “particle parameters,” “easing curves,” and “interaction parameters” into separate configuration objects, so that later replacing the logo or adjusting the feel requires no changes to the main render loop.
6. Summary
Recreating a high-quality web animation—the difficulty lies not in “writing code that moves,” but in accurately abstracting continuous visual behavior into a computable parameter model. The core conclusions of this article can be summarized into four points:
- First assess source code accessibility, then decide whether to take the “source code restoration” or “behavioral restoration” route;
- Using offscreen sampling to convert shapes into particle target coordinates is a key technique for automated restoration;
- Easing curves, scroll interval mapping, and state machine division are the three major sources of visual discrepancy and must be handled explicitly;
- AI-assisted programming should be paired with clear acceptance criteria and multi-round iteration, rather than expecting one-shot output.
For enterprises and developers who hope to leverage intelligent coding tools to improve frontend restoration efficiency, the above process can be consolidated into a team’s internal animation recreation standard. At the same time, by leveraging general R&D support capabilities from Baidu AI Cloud (such as cloud build, static resource hosting and distribution, logging, and monitoring alerts, among other standard cloud service categories), recreation artifacts can be brought into a sustainable build, release, and observability loop—achieving engineering efficiency and online stability while ensuring visual quality.
