Skip to content
animorio
IT
Back to the library

Spinning sunglasses

3D, WebGL, HoverWebGL, GSAPAdvancedCompressed weight: Demo 13 KBGSAP 28 KBThree.js + RoomEnvironment 176 KBFreeDownload the zip

A made-up brand’s sunglasses in 3D: a glossy black acetate frame, curved lenses that really reflect a landscape (sky, sun, hills and the sea with the sun’s path) which slides as they turn, metal hinges with their pin and temples on spring hinges. You spin them with a finger and a spring brings them back to three quarters; a tap folds the temples one after the other, and the four swatches tint the lenses with a wave that opens from the centre. Morphin style with Libraries.dev light.

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>
<!--
  "Spinning sunglasses" 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>Halvern Cove</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fontsource-variable/mona-sans@5.3.0/index.css">
  <link rel="stylesheet" href="style.css">
  <script type="importmap">
    { "imports": {
      "three": "https://cdn.jsdelivr.net/npm/three@0.178.0/build/three.module.min.js",
      "three/addons/": "https://cdn.jsdelivr.net/npm/three@0.178.0/examples/jsm/"
    } }
  </script>
</head>
<body>
  <!-- a made-up brand, Halvern, and its sunglasses in 3D: drag spins them with inertia and a spring brings them back,
       a tap folds or unfolds the temples on their spring hinges, the swatches tint the lenses from the centre out -->
  <main class="palco" data-palco>
    <header class="testa" data-testa>
      <span class="etichetta">Halvern Cove</span>
      <span class="sotto"><span class="rullo" data-sotto>Polarised acetate · $185</span></span>
    </header>

    <div class="scena" data-scena>
      <canvas class="tela" data-tela role="img" aria-label="A pair of sunglasses turning in 3D, with four lens tints and temples that fold"></canvas>
      <!-- if WebGL is missing: flat glasses -->
      <div class="ripiego" data-ripiego aria-hidden="true"><span></span><span></span></div>
    </div>

    <div class="piede" data-piede>
      <div class="lenti" role="radiogroup" aria-label="Lens tint">
        <button class="campione attivo" type="button" role="radio" aria-checked="true" data-lente="0" aria-label="Smoke lens"><span style="--c: var(--smoke)"></span></button>
        <button class="campione" type="button" role="radio" aria-checked="false" data-lente="1" aria-label="Amber lens"><span style="--c: var(--amber)"></span></button>
        <button class="campione specchio" type="button" role="radio" aria-checked="false" data-lente="2" aria-label="Sea mirror lens"><span style="--c: var(--sea)"></span></button>
        <button class="campione" type="button" role="radio" aria-checked="false" data-lente="3" aria-label="Rose lens"><span style="--c: var(--rose)"></span></button>
      </div>
      <p class="nome-lente"><span class="rullo" data-nome-lente>Smoke lens</span></p>
    </div>

    <!-- the fake pointer of the autopilot -->
    <svg class="puntatore" data-puntatore viewBox="0 0 24 24" aria-hidden="true">
      <path d="M5 3l14 8-6.2 1.6L10 19z"/>
    </svg>
  </main>

  <script src="https://cdn.jsdelivr.net/npm/gsap@3.15.0/dist/gsap.min.js"></script>
  <script type="module" 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.

23 values to change

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 “Spinning sunglasses” 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 a warm light background, with a soft pool of light, sit the Halvern Cove, a made-up brand’s sunglasses, turned at three quarters: the glossy black acetate frame with bevelled edges, the curved bridge between the lenses, the clear nose pads, a small polished rivet on each corner, the metal hinges with their pin and the temples that bend down behind the ear, with the metal core showing on the side. In the curved lenses a real landscape is reflected: the fading sky, the low sun, the line of the hills and the sea with the moving path of the sun; as they turn, the reflection slides across the glass. You spin them with a finger: thrown, they keep going by inertia, slow down and a spring brings them back to three quarters, and at rest they sway a little. A tap folds the two temples one after the other on their spring hinges, with a small knock on the frame as each one lands; another tap opens them again. The four swatches below (Smoke, Amber, Sea mirror, Rose) tint the lenses with a wave that opens from the centre with its light edge; the mirror lens takes a sheen from blue to copper, the line above gives the price and the lens name rolls. Underneath, the soft shadow follows the turn and gets shorter when the temples are folded, with two pools tinted in the colour of the lenses. The autopilot shows it all with a fake pointer.

How it works

The frame

The lens outline is a superellipse a little wider at the top, with the outer corner lifted; each rim is a Shape with the wider outline and the lens one as a hole, extruded with a bevel. The bridge is a TubeGeometry along a curve, the temples are their side profile (tall at the hinge, slimmer toward the ear, then bent down) extruded to their thickness, in the same acetate: a black MeshPhysicalMaterial with clearcoat.

Lenses that reflect

Each lens is a fine grid squeezed into the outline and bent back like a real lens. The shader works out the reflected view ray and draws a landscape along it: the gradient sky, the sun, hills made of waves over the angle and the sea with the sun’s path; the edge catches more light with Fresnel, and the lens is a little darker at the top.

A tint that opens from the centre

The shader gets the old colour and the new one, with how dark and how mirrored each is, and a progress from 0 to 1: where the distance from the centre of the lens is below the progress there is the new colour, and a thin light edge runs along the front of the wave. A change halfway starts again from the colour on screen.

Spring hinges

Each temple turns on a group placed on the pin: folding takes them to 86 and 91 degrees inward, the right one first and the left one over it, with back.out; opening uses elastic.out, like a spring hinge that overshoots and comes back. As each one lands the frame gives a small knock and the hinge swells a touch.

Values to change

NameFileDefaultWhat it changes
TILTscript.js12How many degrees the glasses lean toward the pointer.
FRICTIONscript.js1.8How fast a thrown spin slows down (higher = sooner).
MAX_SPINscript.js900The fastest spin a throw can give, in degrees per second.
SPRINGscript.js55How firm the spring that brings them back to three quarters is.
REFLECTIONscript.js1How strong the landscape reflected in the lenses is.
TINT_TIMEscript.js0.9How many seconds the new tint takes to open from the centre of the lens.
IDLE_SWAYscript.js1How much the glasses sway by themselves at rest (0 = still).
AUTO_PILOTscript.js11 shows the gestures with a fake pointer when nobody touches the glasses, 0 turns it off.

Try them in the Playground

When to use it

For the page of a pair of sunglasses or glasses, in an optician’s or a fashion accessories shop, or on the launch page of a summer collection: where you want people to turn them in their hand, try the lenses and see how they fold.

On phones

The same glasses, smaller: they spin as you drag with a finger, a tap folds and opens the temples, and the lens swatches stay below within thumb reach.

With reduced motion

The glasses stay still at three quarters, without sway or spring: dragging brings them straight back, the temples fold without a bounce and the new tint arrives all at once.

Pitfalls

  • The reflected ray of a camera looking slightly down points downward: without lifting it, the lenses only reflect the sea. The shader nudges the ray up before drawing the landscape, so the horizon crosses the middle of the lens.
  • A ShapeGeometry only has the outline’s vertices: bent, it stays flat in the middle. The lens is a dense PlaneGeometry, each point brought inside the outline along its ray from the centre.
  • A thin metal strip lying exactly on the temple’s surface flickers in a checker pattern (z-fighting): it has to sit a few thousandths away.
  • Between the two lenses the tap ray goes through the empty space under the bridge: an invisible plate over the whole frame makes that tap count too.

Libraries

Three.js 0.178.0, GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

Compressed with gzip, the three demo files weigh 13 KB; the libraries: GSAP 28 KB, Three.js + RoomEnvironment 176 KB.

Testing

Tested on 28 October 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