Skip to content
animorio
IT
Back to the library

Chromatic aberration hover

WebGL, Hover, ImagesWebGL, GSAPAdvancedCompressed weight: Demo 6.3 KBGSAP 28 KBFreeDownload the zip

The cover of a photo essay in Halation, a made-up magazine: a real photo of a street at night under blue and magenta neon. Move the mouse over it and a WebGL shader pulls red, green and blue apart along the direction and with the strength of the movement, more around the pointer like a soft lens, and when you stop the channels come back together on a measured spring; the title beside it shifts one pixel the other way and the photo edge picks up a thread of the three colours only when the split is strong.

The code

A folder that runs on its own: index.html, style.css, script.js and the libraries from a CDN. The React and Vue tabs hold the same demo as a ready component, which switches its animations off when it leaves the page.

<!doctype html>
<!--
  "Chromatic aberration hover" from Animorio · https://animorio.com
  License: free on your own sites and your clients’ sites, paid work included.
  Not for resale, redistribution, templates or code collections · https://animorio.com/en/license/
-->
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Chromatic aberration hover</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fontsource-variable/mona-sans@5.3.0/standard.css">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fontsource-variable/fraunces@5.3.0/index.css">
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <main class="stage" data-stage>
    <article class="cover" data-cover>
      <figure class="photo" data-photo>
        <div class="photo__frame" data-frame>
          <img class="photo__img" data-img src="strada.webp" alt="A city street at night, wet asphalt under blue and magenta neon lights" width="960" height="721" decoding="async">
          <canvas class="photo__gl" data-gl aria-hidden="true"></canvas>
          <span class="photo__fringe" aria-hidden="true"></span>
        </div>
        <figcaption class="photo__cap"><span>Photograph</span><span data-caption>Blue hour, wet asphalt</span></figcaption>
      </figure>

      <div class="text" data-text>
        <p class="mag"><span class="mag__name" data-brand>Halation</span><span class="mag__issue">Night issue</span></p>
        <h1 class="title" data-title>The street that<br>never dries</h1>
        <p class="lede">Neon, rain and the long walk home. A photo essay on the hour when a city turns its lights on.</p>
        <dl class="meta">
          <div><dt>Category</dt><dd>Cities</dd></div>
          <div><dt>Year</dt><dd>2026</dd></div>
          <div><dt>Read</dt><dd>9 min</dd></div>
        </dl>
        <a class="read" href="#" data-read>
          <span>Read the essay</span>
          <svg class="read__arrow" viewBox="0 0 16 16" aria-hidden="true"><path d="M3 8h9.5M8.5 4l4 4-4 4" /></svg>
        </a>
      </div>
    </article>
  </main>

  <script src="https://cdn.jsdelivr.net/npm/gsap@3.15.0/dist/gsap.min.js"></script>
  <script src="script.js"></script>
</body>
</html>

Playground

Change values, colours and text with the controls and watch the animation respond live. Or write in the code yourself. Then download the folder with your changes.

30 values to change

Works with Claude, Claude Code, ChatGPT, Cursor, VS Code, Windsurf, Codex, Gemini CLI

Or ask your AI assistant for it

With the Animorio connector, Claude Code, ChatGPT, Cursor or VS Code take it from here, guide included, and fit it into your project. Paste this request:

Take “Chromatic aberration hover” from Animorio and fit it into my site
Platform licenseFree on your sites and your clients’ sites. Want it inside a website builder, a template platform or a client dashboard? There’s a license for agencies and platforms.

What it does

On an almost black background, the cover of an essay in Halation, a made-up magazine: on the left a real photo of a city street at night, wet asphalt and blue and magenta signs, with its caption below; on the right the magazine name in italics, «Night issue», the large title «The street that never dries», two lines of introduction, category, year and reading time, and the Read the essay button. Move the mouse over the photo and the three colours come apart: red runs ahead along the movement, blue falls behind, green stays, and the split is stronger around the pointer and lighter further away. The faster the mouse, the wider the split, up to a limit. Stop, and the channels come back together on a spring that overshoots by a breath and settles. Meanwhile the title block shifts one pixel the other way, the photo edge picks up a red and blue thread only when the split is strong, the photo breathes by a thousandth and a very light grain keeps it alive. The autopilot passes over the photo by itself, fast and slow, when nobody touches it.

How it works

The photo and the canvas

The photo is a real file in the folder, strada.webp, shown as an <img> with object-fit: cover. Above it sits a WebGL canvas as big as the frame: once the photo has loaded it becomes a texture, and the shader redraws it with the same cover fit, so the two match to the pixel. Until the texture is ready, or without WebGL, you see the clean <img>.

The three channels

For each point the shader reads the photo three times: red shifted by +o, green in place, blue shifted by −o. The vector o is the split multiplied by a weight that is 1 around the pointer and falls off on a Gaussian to EDGE far away: a soft lens. On top, a grain made from a hash of the point that changes 24 times a second.

Speed and spring

Every frame we measure how many pixels the pointer travelled, scaled to a sixtieth of a second so it behaves the same at any refresh rate: times STRENGTH it becomes the target split, kept under MAX_SPLIT. The real split chases the target on a spring (velocity × DAMPING + distance × SPRING); the target drops back to zero by itself when the pointer stops, and the spring brings the channels back together with a small overshoot.

The details around

The same strength, from 0 to 1, goes into a CSS variable, --sep: the red and blue edge of the photo has opacity --sep squared, so it shows only when the split is strong. The title block moves 1.4 pixels the other way, and the photo breathes by a thousandth on a slow sine.

The autopilot

A repeating GSAP timeline moves a fake pointer over the photo, with slow passes and quick flicks. A real movement stops it, and it restarts after six quiet seconds with gsap.delayedCall.

Values to change

NameFileDefaultWhat it changes
BRANDscript.js'Halation'The name of the made-up magazine, above the title.
STRENGTHscript.js2.6How far the channels split for each pixel of pointer speed.
MAX_SPLITscript.js34The strongest split, in pixels.
LENSscript.js0.42The radius of the soft lens around the pointer.
EDGEscript.js0.35How much the channels split far from the pointer.
SPRINGscript.js0.11The spring that brings the channels back together.
DAMPINGscript.js0.8The spring damping: lower means less overshoot.
GRAINscript.js0.032The grain over the photo.

Try them in the Playground

When to use it

For an article cover, a portfolio project or an electronic music event poster: the photo reacts to the mouse without breaking and comes back clean as soon as you stop.

On phones

The same effect with a finger dragging over the photo; the photo goes on top and the text below, the introduction hides to fit the box.

With reduced motion

No split: the photo stays clean, on hover it brightens slightly in a fade, and everything arrives in a fade.

Pitfalls

  • The <img> photo and the shader photo must use the same cover fit, otherwise you see a jump on hover.
  • Speed must be measured over time, not per event: mouse events arrive at different rates on each screen, and at 120 Hz the split would be half.
  • Opened from file:// the browser won’t let the photo become a texture: the clean <img> stays.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0, Fraunces (font variabile) 5.3.0.

Compressed with gzip, the three demo files weigh 6.3 KB; the libraries: GSAP 28 KB.

Testing

Tested on 26 November 2026

  • Desktop: Done
  • Phone: Done
  • Reduced motion: Done
  • Safari on iPhone: To do

License

Use it in your own projects and in your clients’ projects. Do not resell it or redistribute it as is. GSAP stays under its own Standard license. Full license.

All animations