Ripple Distortion HTML
Create a responsive image surface whose pixels refract along fading concentric ripples. Preserve the target page's layout and visual language; the effect is an enhancement, not a replacement for its content.
Build the effect
- Copy
assets/ripple-distortion.jsbeside the target HTML, or adapt theRippleDistortionclass into the existing JavaScript bundle. - Give the host element an explicit, non-zero size and instantiate the browser-global class:
html<div id="ripple-hero" aria-label="Abstract landscape"></div> <script src="./ripple-distortion.js"></script> <script> const ripple = new window.RippleDistortion('#ripple-hero', { src: './hero.jpg', trigger: 'hover', strength: 0.2, rings: 4 }); </script>
- Start from the source-matched defaults. Change only parameters that serve the requested art direction. Read
references/options.mdfor parameter behavior, safe ranges, presets, and the public API. - Preserve the module's image fallback, resize handling, offscreen pause, reduced-motion behavior, and
destroy()cleanup when integrating it into another codebase.
Non-negotiable implementation details
- Use a two-pass displacement pipeline: accumulate ripple masks in an offscreen texture, then use that texture to offset image sampling in the final pass. CSS filters alone do not reproduce the refractive look.
- Keep pointer coordinates local to the host element and convert the vertical axis for WebGL. The effect must still align after scrolling or resizing.
- Render the image with cover semantics. Do not stretch it to the container's aspect ratio.
- Keep a visible
<img>fallback until WebGL has uploaded the source texture. Remote images need permissive CORS headers; if they do not have them, recommend a same-origin image rather than hiding the failure. - Keep the canvas decorative (
aria-hidden="true") and put the image description on the host witharia-label. - Honor
prefers-reduced-motion: show the static image and suppress new ripples. - For multiple instances or client-side page changes, retain each returned instance and call
destroy()before removing its host.
Verify before delivery
- Test hover and click triggers at the container's corners as well as its center.
- Resize the host and confirm that the image remains cover-cropped and the ripple stays under the pointer.
- Confirm the static fallback appears when WebGL is unavailable or image texture upload fails.
- Check that reduced-motion mode produces no new distortion.
- Use
assets/demo.htmlas the visual reference and integration example, not as mandatory page styling.
Scope and provenance
This skill implements only the Ripple Distortion interaction studied at https://reactbits.dev/animations/ripple-distortion. The bundled module is an original plain-WebGL adaptation; it does not require React, OGL, or code from other React Bits effects. Do not present it as the upstream React component.


