Skip to content
animorio
IT
All components

Sun brightness slider

Sliders, Hover, PhysicsGSAP, CSS onlyMediumCompressed weight: Demo 7.7 KBGSAP 28 KBFreeDownload the zip

The vertical brightness slider of a control centre, on very light grey, in the style of one-gesture micro-interactions: a wide pill that fills from the bottom as you drag it, with inertia when flicked and a small elastic stretch past the ends. The sun at the bottom opens its rays one after another as it rises, the phone beside it really gets brighter and Night Shift warms the colours.

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>
<!--
  "Sun brightness slider" 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>The brightness slider with a sun that opens its rays</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fontsource-variable/mona-sans@5.3.0/wdth.css">
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <main class="stage" data-stage>
    <!-- a control centre: drag the wide pill up and down, the screen beside it really gets brighter,
         the sun opens its rays, and Night Shift warms the colour -->
    <section class="set" data-card aria-label="Display brightness">
      <figure class="screen" data-screen aria-hidden="true">
        <div class="screen__glass">
          <div class="app">
            <div class="app__bar"><span class="app__logo"></span><span class="app__line w40"></span><span class="app__avatar"></span></div>
            <div class="app__hero"><span class="app__sunset"></span><span class="app__hill"></span></div>
            <p class="app__title">Evening, Noa</p>
            <span class="app__line w70"></span>
            <span class="app__line w50"></span>
            <div class="app__chips"><span></span><span></span><span></span></div>
          </div>
          <div class="screen__warm" data-warm></div>
          <div class="screen__dim" data-dim></div>
          <div class="screen__shine"></div>
        </div>
        <span class="screen__notch"></span>
      </figure>

      <div class="panel" data-panel>
        <div class="panel__head">
          <p class="panel__label">Display</p>
          <p class="panel__value" aria-hidden="true"><span class="digits" data-digits></span><span class="pct">%</span></p>
        </div>

        <div class="pill" data-pill role="slider" tabindex="0" aria-label="Brightness" aria-orientation="vertical" aria-valuemin="0" aria-valuemax="100" aria-valuenow="45">
          <div class="pill__track" data-track>
            <div class="pill__fill" data-fill><span class="pill__edge"></span></div>
          </div>
          <svg class="sun" data-sun viewBox="0 0 32 32" aria-hidden="true">
            <circle class="sun__core" data-core cx="16" cy="16" r="4.6"></circle>
            <g class="sun__rays" data-rays></g>
          </svg>
        </div>

        <button class="night" type="button" data-night aria-pressed="false">
          <svg viewBox="0 0 24 24" aria-hidden="true"><path class="night__moon" d="M15.6 4.4a7.6 7.6 0 1 0 4 11.9A6.2 6.2 0 0 1 15.6 4.4z"></path></svg>
          <span class="night__text"><span class="night__name">Night Shift</span><span class="night__state" data-state>Off</span></span>
        </button>
      </div>
    </section>

    <svg class="ghost" data-ghost viewBox="0 0 24 24" aria-hidden="true"><path d="M5 3.2 19.2 11l-6.3 1.6-3.3 5.9Z"></path></svg>
  </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.

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 “Sun brightness slider” 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 very light grey background there are two pieces side by side: on the left a phone with an app on (the top bar, a violet and orange sunset behind a hill, Evening, Noa and a few lines), on the right the dark control centre panel with the word Display, the percentage in digits and a wide pill. You take the pill and drag it up and down: the white part fills it from the bottom without jumping to where you touch it, the track widens slightly while held, and the phone beside it really brightens and darkens, down to an almost full black at zero. The percentage rolls digit by digit. At the bottom of the pill the sun opens its rays one after another as the brightness rises, the circle in the middle grows a little, and once the white part covers it the sun turns from light to dark. Flicked, the pill carries on by itself and slows with friction; pulled past the top or the bottom it stretches a few pixels towards the hand and comes back on an almost unbouncy spring, and at the very top or bottom the sun gives a small jolt. Night Shift, below, turns on the amber: the button goes orange with a full moon, the word Off rolls into On, the filled part of the pill warms up and a warm veil falls over the phone. The autopilot pointer raises the light, pulls past the top, flicks the pill down, turns Night Shift on, raises it a little more, turns it off and goes back to where it started.

How it works

The pill taken where it is

On touch the distance between the finger and the edge of the filled part is remembered (grabOff), so the brightness does not jump to the touched point but follows the finger from where it was. The value is the distance from the bottom of the track divided by its height, plus that distance.

Inertia and spring

While dragging, the speed is measured and blended with the previous one so it does not jitter. Let go, the pill carries on on the GSAP ticker with its speed dropping by e to the minus FRICTION times the time; past the ends a nearly critical spring (stiffness 260, damping 30) brings it back to the top or bottom.

The elastic at the ends

Past the top or bottom the extra is squashed with a hyperbolic tangent, STRETCH times tanh of the excess in pixels over four STRETCH, and becomes a scaleY of the pill anchored on the opposite side.

The sun and the screen

Each ray is an SVG line that lengthens once the brightness passes its threshold, staggered round the circle; the sun follows the value a touch behind, so the rays open softly. The screen has a black veil on top with opacity (1 minus the value) times DARKEST, and Night Shift an orange veil in multiply.

Values to change

NameFileDefaultWhat it changes
STARTscript.js45The starting brightness, from 0 to 100.
FRICTIONscript.js7How quickly a flicked pill stops: higher stops sooner.
STRETCHscript.js14How many pixels at most the pill stretches when pulled past the ends.
DARKESTscript.js0.82How dark the screen gets at zero brightness, from 0 to 1.
WARMTHscript.js0.34How much Night Shift warms the colours, from 0 to 1.
RAYSscript.js8How many rays the sun has.
STEPscript.js5How much the arrow keys move the brightness.

Try them in the Playground

When to use it

In the control centre of an app or a system, in a display settings panel, in the control of home lights or a smart lamp: anywhere a quantity is set with a single gesture and the result should show right beside it.

On phones

Phone and panel are sized on the window height (the min of 64vh, 340 pixels and 92vw), so they sit side by side even in the short phone box. With a finger the pill drags and flicks as with the mouse, without scrolling the page.

With reduced motion

No inertia, elastic or jolts: the pill follows the finger and stops where it is let go, the digits change without rolling, the Night Shift colours fade in and the autopilot shows the values one after another.

Pitfalls

  • Let go past an end, the pill must come back from zero speed on a nearly critical spring: with the pull’s speed and a soft spring it bounced halfway down.
  • The sun is centred with a margin, not translateX: GSAP animates its scale and its transform would wipe the CSS one.
  • Without touch-action: none on the pill a phone takes the vertical drag as a page scroll and sends pointercancel halfway.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

Compressed with gzip, the three demo files weigh 7.7 KB; the libraries: GSAP 28 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 components