webdevpuneet.com

Physics2D Particle Burst — Free GSAP Physics Snippet

Physics2D Particle Burst · Animations · Plain HTML, CSS & JS · Live preview

CategoryAnimations

Copy & paste

Source Code

<div class="p2b-stage" id="p2bStage">
  <p class="p2b-hint">Click anywhere — every particle gets a velocity, an angle, and gravity.</p>
</div>

Extend with AI

Take This Snippet Further With AI

The AI prompt for this one is for Patreon supporters ($3 a month, 7 days free), along with a site with no ads. Supporters enter the passcode once and it is remembered in this browser.

· Become a supporter

What's included

Features

Launch-condition motion
Speed, angle, gravity — no destinations.
True parabolas
Integrated projectile trajectories per particle.
Gravity as easing
ease: 'none' lets acceleration shape motion.
Six-way randomness
Size, color, speed, angle, spin, lifetime.
Inline random strings
'+=random(-180,180)' spins per target.
Self-cleaning DOM
Every tween removes its own particle.
Press-instant bursts
pointerdown beats click latency.
Any-target physics
Works on DOM, SVG, or WebGL props.

About this UI Snippet

Physics2D Particle Burst — Launch-Condition Animation, Not Keyframes

Screenshot of the Physics2D Particle Burst snippet rendered live

Every other tween in this library animates from a start value to an end value. This one doesn't: click the stage and 28 particles are given *launch conditions* — a speed, a direction, and gravity — and GSAP's Physics2DPlugin (free on the CDN since 3.13) integrates the resulting parabolic trajectories. No destination is ever specified; where each particle lands is an outcome, not an input. That inversion is what makes physics-based motion feel organic where eased tweens feel staged.

velocity + angle + gravity is the whole model

physics2D takes initial velocity (pixels/second), a launch angle (degrees, where 270 is straight up in screen coordinates), and a gravity acceleration. Each frame it advances position along the velocity vector while gravity bends it downward — projectile motion, integrated for you. Randomizing velocity (180–480) and angle (230–310, an upward cone) per particle produces the natural spread of a real burst: fast particles fly wide and high, slow ones flop shortly, all on true parabolas rather than eased arcs.

ease: 'none' is mandatory here

Easing curves remap time — which would distort the physics. With ease: 'none', simulation time runs linearly and the *acceleration itself* provides all the perceived easing: particles launch fast, hang weightless at apex, and accelerate into the fall. That's why physics motion needs no easing — gravity *is* the ease.

gsap.utils.random powers the variety

Size, color rotation, launch speed, direction, spin, and lifetime are all drawn from gsap.utils.random ranges — six randomized dimensions per particle. The string form rotation: '+=random(-180, 180)' shows GSAP's inline random syntax: a relative spin unique per particle without writing a loop variable. Uniform particles read as a rigid fountain; layered randomness reads as confetti.

Particles are disposable DOM, cleaned by their own tween

Each dot is a tiny absolutely-positioned div appended on click and removed in its own onComplete (via this.targets()[0]), so the DOM returns to baseline after every burst — no pooling, no leaks, no cap logic. At 28 particles per click with transform-and-opacity-only animation, even rapid clicking stays comfortably within compositor budget; past a few hundred simultaneous particles you'd graduate to canvas.

pointerdown, not click, for responsiveness

Bursts fire on pointerdown so the explosion lands at the instant of press — the 100–300ms a click waits for release makes celebratory feedback feel detached. Coordinates convert from client space to stage space via getBoundingClientRect, so the burst originates exactly under the pointer regardless of page scroll.

Where physics beats confetti libraries

Libraries like canvas-confetti own their canvas and their look. Physics2D applies the same math to *any tweenable target* — DOM nodes, SVG elements, WebGL objects — so branded shapes, emoji, or product icons can explode with identical physics, and every burst composes with the rest of your GSAP timeline system.

Customizing it

Narrow the angle cone for directional cannons, raise gravity for heavier debris, or swap dots for emoji spans. Related celebration and physics patterns: confetti button, confetti celebration card, gravity-and-collision in physics balls, and friction-based motion in physics props pucks.

Step by step

How to Use

  1. 1
    Add the GSAP CDNsInclude gsap and Physics2DPlugin from the CDN panel.
  2. 2
    Paste HTML, CSS, and JSA dark stage renders with a crosshair cursor.
  3. 3
    Click anywhere28 particles burst upward from the pointer.
  4. 4
    Watch the arcsGravity bends every trajectory into a parabola.
  5. 5
    Click rapidlyEach burst cleans its own DOM on completion.
  6. 6
    Tune the physicsVelocity range, angle cone, and gravity are one object.

Real-world uses

Common Use Cases

Order confirmation celebrations
Burst confetti when an order completes, giving each of 28 particles a launch speed, angle and gravity so they trace true parabolas.
Gamified quiz rewards
Reward taps in quizzes and next to a streak tracker, where every click anywhere on the stage detonates a fresh burst.
Like explosions
Release particle hearts from a like burst button, with six-way randomness in size, colour, speed, angle, spin and lifetime.
Interactive hero toys
Offer a landing page toy that cousins physics balls, using ease: 'none' so gravity itself shapes the motion.
Friction contrasts
Compare with physics props pucks, which show friction instead of gravity using the same launch-condition idea.

Got questions?

Frequently Asked Questions

Normal tweens interpolate between known start and end values. physics2D takes launch conditions — velocity in px/sec, an angle in degrees, and gravity — and integrates the trajectory frame by frame; the end position is an outcome, never an input. That's why bursts look organic: each particle follows a genuine parabola instead of an eased path to a chosen point.

Easing remaps the tween's time, which would warp the simulation — gravity computed against distorted time stops looking like gravity. With linear time, the acceleration itself produces all perceived easing: fast launch, weightless hang at apex, accelerating fall. In physics animation, the forces are the easing curve.

Degrees in screen space: 0 points right, 90 points down (y grows downward in browsers), 270 points straight up. The demo's 230–310 range is an 80° cone centered on "up," so particles spray skyward with natural spread. Narrow the range for a cannon, use 0–360 for an omnidirectional explosion.

Not at this scale: each burst appends 28 tiny divs animated only via transform and opacity (compositor work), and every tween's onComplete removes its own element, so the DOM returns to baseline within two seconds of the last click. Hundreds of simultaneous particles remain fine; thousands is when a canvas approach earns its complexity.

Yes — Physics2D animates transforms on any target, so swap the div for a span containing 🎉, an inline SVG star, or an img of your logo; the identical launch math applies. That's the practical edge over confetti libraries, which own their canvas and particle look: here your branded elements are the physics objects.

Register the plugin at module scope and fire bursts from a pointerdown handler that appends particles to a stage ref — imperative DOM is correct here, since routing 28 short-lived particles through framework state would re-render per burst for nothing. Add a cleanup that kills active tweens on unmount so removals don't target dead nodes. The stage styles map directly to Tailwind.