Hover✨ Premium

Rope Physics

A 25-segment Verlet rope with both ends anchored responds to mouse dragging in real time: the length constraint is resolved in 10 iterations per frame, gravity pulls nodes downward. Sharp on Retina, loop paused off-screen, static rope under reduced motion.

CanvasVerletDraggable

Updated

This effect is part of Effect.Labs — 840 vanilla effects, some free, some premium. Hover has 48 effects, including 5 free. Explore the category →

3 usage examples

Full-screen hero section for Tensio motion design studio — rope as animated background — Rope Physics example 1

① Full-screen hero section for Tensio motion design studio — rope as animated background

WhenThe visitor arrives on the studio homepage; the rope is already curved by gravity and can be dragged at any point.
WhyA Verlet rope in the hero background embodies the studio's specialty (tension, fluid movement) without a word of description.
SettingsCanvas 300 px at top: 40 px in position: absolute; hero text at z-index: 10; rope in fuchsia (#d946ef).
Interactive widget in the MOOC lesson 'Verlet Integration and Catenary Curve' — Rope Physics example 2

② Interactive widget in the MOOC lesson 'Verlet Integration and Catenary Curve'

WhenThe student drags any node of the rope to observe how the catenary shape changes with the hand position.
WhyA Verlet rope reproduces the catenary curve of a cable under its own weight: no static drawing shows the deformation in real time.
Settings2-column flex container: 220 px course text + flex:1 canvas widget; canvas at height: 100% !important to fill the panel.
Mini-game 'Tug of War' — two teams compete by pulling the centre node toward their side — Rope Physics example 3

③ Mini-game 'Tug of War' — two teams compete by pulling the centre node toward their side

WhenThe player drags the centre node toward their team and holds it on their side for 3 seconds to score a point.
WhyA Verlet rope with two fixed anchors whose centre you pull is the natural representation of tug of war; the physical challenge is immediate.
Settings52 px scoreboard + flex:1 play zone + 50 px footer; team indicators positioned over the anchors via position: absolute.

How it works

The .fx-0390-root wrapper contains a .fx-0390-canvas that is 100 % wide by 300 px tall. At init, the script measures the width, applies devicePixelRatio and builds 26 nodes spaced 12 px apart. Nodes 0 and 25 are pinned at 20 % and 80 % of the width; the 24 others are free.

The loop uses Verlet integration: each frame, each free node computes its implicit velocity from its previous position (vx = (x − oldX) × 0.99), adds gravity (0.5 px/frame), then resolves the segment length constraint in 10 iterations. Scaling by dt / 16.67 (capped at 50 ms) ensures the simulation does not diverge after a background tab.

A mousedown (or touchstart) finds the nearest node within 15 px and attaches it to the pointer; mousemove (or touchmove) moves that node. An IntersectionObserver watches the root to pause the loop off-screen. Under reduced motion, the rope is drawn in its rest position with no loop.

Accessibility

  • Reduced motion: under prefers-reduced-motion: reduce, the loop does not start and the rope is drawn at its rest position. The effect is visible and readable.
  • Keyboard: the interaction requires a mouse or finger (dragging a rope node). There is no natural keyboard equivalent for a canvas drag. Keyboard users cannot deform the rope.
  • Touch: touch-action: none on the canvas prevents page scrolling when a finger slides over it. The effect responds to touch on mobile.
  • Decorative role: the canvas carries no text content. If the rope represents a named cable or path, expose that information as text nearby.

Browser compatibility

Canvas 2D (devicePixelRatio, IntersectionObserver, matchMedia), no dependency. IntersectionObserver available since Chrome 51, Firefox 55 and Safari 12.1. Not measured in Firefox and WebKit.

Chrome 51+✓ Full (measured)
Firefox 55+✓ Full (not measured)
Safari 12.1+✓ Full (not measured)
Edge 79+✓ Full (Chromium engine)
Mobile iOS 12.2+✓ Full (not measured)
Android Chrome 51+✓ Full (measured on Chromium)

Without JavaScript, the canvas stays empty. Without IntersectionObserver, the simulation runs off-screen too. Without matchMedia, the rope animates even under reduced motion.

The code

HTML structure to paste into your page (the CSS + JS come with your purchase):

index.html — structure
<div class="fx-0390-root"><div class="physics-container"><canvas class="fx-0390-canvas"></canvas><span class="info-label">Help text</span></div></div>

One-time payment, no subscription — the code is yours forever

Customize

Options passed to the API or data-* attributes:

Option / propertyDefaultEffect
Number of segments (JS — SEGS = 25) 25 segments 10 segments give a coarse but very fast rope; 50 give a finer, more supple rope (more computation).
Segment length (JS — SEGLEN = 12) 12 px 8 px for a shorter, tighter rope; 18 px for a looser, more drooping rope.
Gravity (JS — n.y += vy * scale + 0.5 * scale) 0.5 px/frame 0.2 for an almost horizontal rope; 1 for a very heavy rope that falls fast.
Rope colour (JS — ctx.strokeStyle = '#d946ef') #d946ef (fuchsia) Replace with your brand colour. Thickness is controlled via ctx.lineWidth = 6.
Anchor positions (JS — x0 = 0.2 * W, x1 = 0.8 * W) 20 % and 80 % of the width 0 * W and 1 * W to anchor the rope at the extreme edges of the canvas.

FAQ

Yes. The basic Verlet algorithm does not handle self-collisions. To prevent crossings you would need to add segment-crossing detection and constrain nodes to stay on one side of each segment.
Nodes 0 and SEGS are pinned. Their positions come from x0 and x1 at init. For movable anchors, remove pinned: true on those nodes and update them in the loop.
A single iteration is not enough to keep segment lengths stable: nodes near the anchors barely move, those in the middle move too far. Ten iterations give a visually stable result. Reducing to 5 speeds up computation at the cost of a less rigid rope.