Skip to content
animorio
IT
Back to the library

Day-night page flip

Transitions, HoverGSAP, CanvasMediumCompressed weight: Demo 10 KBGSAP 28 KBFreeDownload the zip

The home page of Halcyon Star Club, a made-up astronomy night, all in black and white and in a monospaced type, like the one of Star Party Silverlake. In the ticker at the bottom sits the pill switch: the knob runs on a spring and one pixel too far, the sun and the moon swap with a turn, and the page flips not all at once but with a wave leaving the knob: the sky turns over in a circle, the stars become ink dots, and ticker, panel and header change colour the moment the wave reaches them. Touched, the switch says MANUAL and a thin line wears down; when it ends, the page goes back by itself to the theme of the real sun, worked out from the sun’s altitude.

Rebuilt from scratch studying starpartysl.com by Hayda Studios: the idea is theirs; code, copy and images are ours. Read how it’s made

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>
<!--
  "Day-night page flip" 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 day and night switch that flips the whole page and goes back to the real sun</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fontsource-variable/geist-mono@5.3.0/index.css">
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <!-- the home page of Halcyon Star Club, a made-up monthly astronomy night, in black and white: the switch in the
       ticker flips the whole page between night and day, not all at once but in a staggered choreography (the sky
       from the knob outwards, then the header, the panel and the ticker); touched, it says MANUAL and a thin line
       drains, then the page goes back by itself to the theme of the real sun, worked out with the sun's altitude -->
  <main class="page" data-page>
    <div class="sky layer" data-layer="sky">
      <span class="sky__wipe" data-wipe aria-hidden="true"></span>
      <canvas class="sky__stars" data-stars aria-hidden="true"></canvas>
    </div>

    <header class="head layer" data-layer="head">
      <a class="brand" href="#" aria-label="Halcyon Star Club">
        <svg class="brand__mark" data-mark viewBox="0 0 24 24" aria-hidden="true">
          <path d="M12 1.8 13.6 10.4 22.2 12 13.6 13.6 12 22.2 10.4 13.6 1.8 12 10.4 10.4Z"></path>
          <path class="brand__small" d="M19.2 3.4 19.8 5.6 22 6.2 19.8 6.8 19.2 9 18.6 6.8 16.4 6.2 18.6 5.6Z"></path>
        </svg>
        <span class="brand__name">Halcyon<span class="brand__sub">Star Club</span></span>
      </a>
      <nav class="nav" aria-label="Main">
        <a href="#">Nights</a>
        <a href="#" class="nav__wide">Telescopes</a>
        <a href="#" class="nav__join">Join</a>
      </nav>
    </header>

    <section class="panel layer" data-layer="panel" data-panel aria-label="This month">
      <button class="panel__close" type="button" data-close aria-label="Close panel">
        <svg viewBox="0 0 12 12" aria-hidden="true"><path d="M2.5 2.5 9.5 9.5M9.5 2.5 2.5 9.5"></path></svg>
      </button>
      <span class="label">This month</span>
      <h1 class="panel__title">Late-autumn sky<br>over the reservoir</h1>
      <div class="panel__row">
        <span class="panel__when">SAT · NOV 21 · 8 PM</span>
        <a class="panel__book" href="#">Book a spot
          <svg viewBox="0 0 12 12" aria-hidden="true"><path d="M3 9 9 3M4.2 3H9v4.8"></path></svg>
        </a>
      </div>
    </section>

    <footer class="ticker layer" data-layer="ticker">
      <div class="ticker__col">
        <span class="label">Local time</span>
        <span class="value clock" data-clock>08:41:07 PM</span>
        <span class="sub" data-date>SAT · NOV 14, 2026</span>
      </div>

      <div class="ticker__col ticker__col--sun">
        <span class="label">The sun</span>
        <svg class="gauge" viewBox="0 0 96 30" aria-hidden="true">
          <path class="gauge__arc" d="M6 28 A42 24 0 0 1 90 28"></path>
          <path class="gauge__line" d="M2 28H94"></path>
          <g data-sun>
            <circle class="gauge__sun" r="3.2" cx="0" cy="0"></circle>
          </g>
        </svg>
        <span class="sub" data-alt>12.4° BELOW</span>
      </div>

      <div class="ticker__col ticker__col--right">
        <button class="switch" type="button" role="switch" aria-checked="true" aria-label="Night sky" data-switch>
          <span class="switch__word switch__word--night" data-word-night>Night</span>
          <span class="switch__word switch__word--day" data-word-day>Day</span>
          <span class="switch__knob" data-knob>
            <span class="switch__squash" data-squash>
              <svg class="switch__icon switch__icon--sun" data-icon-sun viewBox="0 0 16 16" aria-hidden="true">
                <circle cx="8" cy="8" r="3"></circle>
                <path d="M8 1.2V3M8 13v1.8M1.2 8H3M13 8h1.8M3.2 3.2l1.3 1.3M11.5 11.5l1.3 1.3M3.2 12.8l1.3-1.3M11.5 4.5l1.3-1.3"></path>
              </svg>
              <svg class="switch__icon switch__icon--moon" data-icon-moon viewBox="0 0 16 16" aria-hidden="true">
                <path d="M10.6 2.2a6 6 0 1 0 3.2 9.6A5 5 0 0 1 10.6 2.2Z"></path>
              </svg>
            </span>
          </span>
        </button>
        <span class="status" data-status>
          <span class="status__text" data-status-text>AUTO · FOLLOWS THE SUN</span>
          <span class="status__line" aria-hidden="true"><span data-drain></span></span>
        </span>
      </div>
    </footer>
  </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.

34 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 “Day-night page flip” 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 black sky of a hundred and fifty twinkling stars, with three small constellations in thin lines, sits the page of Halcyon Star Club: at the top the star mark with «Nights», «Telescopes» and «Join», on the left the panel of the month’s night («Late-autumn sky over the reservoir», Saturday 21 November at 8 pm, «Book a spot») with its close button, at the bottom the ticker with the clock to the second, the sun on a small arc with how many degrees it is above or below the horizon, the switch and the word AUTO. When the switch turns, a circle leaves the knob and turns the sky from black to white (or back) and each part of the page changes colour when the circle touches it; the mark makes a quarter turn. The word becomes MANUAL with the seconds counting down and the line below wears down; at zero the page goes back to the theme the real sun says.

How it works

The sun’s altitude

As on the site, sunAltitude() does the astronomy: mean anomaly, equation of the centre, ecliptic longitude, declination and sidereal time, then the altitude with the latitude. Above -0.833 degrees (the sun’s edge rising, with refraction) it is day. The place is neither asked nor shown: the longitude comes from the visitor’s time zone (15 degrees an hour) and the latitude is a middle one.

Each part has its own two colours

Sky, header, panel and ticker each have their own --bg and --fg variables, and everything else uses them (edges, knob, icons). GSAP tweens them one by one: so the page does not change all at once but part by part.

The wave leaving the knob

On the sky a veil of the new colour opens with clip-path: circle() from the knob’s centre to the farthest corner, with sine.inOut. Since the radius is R(1 - cos(πt/T))/2, the moment it reaches a distance d is T·acos(1 - 2d/R)/π: each part starts changing colour exactly when the wave reaches its nearest point and ends when it passes the farthest.

The stars on the right side

Stars and lines are on a canvas. On every frame each star checks whether it is inside the circle: inside it takes the new colour, outside the old one, so they flip the moment the wave passes them. Each star twinkles with its own sine and follows the pointer by its depth.

The knob on a spring

The run goes one pixel too far with power3.out and comes back with sine.inOut; meanwhile the knob stretches halfway and turns round again with an elastic. The sun leaves with a 90 degree turn and the moon comes in turning from the other side, with back.out. Pressed it squashes, under the pointer it leans three pixels towards the other side.

MANUAL, then the sun again

Like the site’s spslSkyManual variable, the manual choice stops the automatic check; here though it lasts a few seconds: a one-pixel line wears down with a linear tween and at zero the page goes back by itself to the sun’s theme. Turn it back to the sun’s side and it says AUTO at once.

Values to change

NameFileDefaultWhat it changes
RETURN_AFTERscript.js5How many seconds the manual choice lasts before the page goes back by itself to the theme of the real sun.
WIPEscript.js1.15How many seconds the wave takes to leave the knob and flip the whole sky.
LAYER_TIMEscript.js0.42How many seconds each part (header, panel, ticker) takes to change colour when the wave reaches it.
KNOB_TIMEscript.js0.62How long the knob’s run lasts, in seconds.
OVERSHOOTscript.js1How many pixels the knob goes past before settling.
SQUASHscript.js0.26How much the knob stretches halfway (0 = never).
STARSscript.js150How many stars in the sky behind the page.
TWINKLEscript.js0.45How much the stars twinkle (0 = still).
DRIFTscript.js6How many pixels the sky follows the pointer.
AUTOPILOT_WAITscript.js2.4How many seconds the autopilot waits before turning the switch by itself.

Try them in the Playground

When to use it

For sites that change theme by themselves with the time of day (an observatory, an evening event, a bar that turns into a club at night, a hotel, a weather or sleep app) and for every dark-mode switch that should feel like a gesture and not a flash: the wave from the knob and the parts changing one after the other carry over to any page.

On phones

The same gesture with adapted sizes: the header keeps the mark and «Join», the panel moves to the centre and is sized on the height with clamp, the ticker keeps the clock, the switch and the word (the sun on its arc hides under 620 pixels). The wave always leaves the knob and reaches the farthest corner, recomputed if the window changes size. A finger taps like the mouse.

With reduced motion

No wave and no running knob: the knob is already on the right side, icons and words cross-fade and the whole page fades from one theme to the other in 0.45 s. The stars do not twinkle or follow the pointer.

Pitfalls

  • White text on the white sky: if header and panel changed colour all together after the wave, for a moment the white words would sit on the already white sky and vanish. That is why each part starts when the wave touches it, with the times found by inverting the curve.
  • The mark’s quarter turn: the four-pointed star goes back to zero degrees after the turn, and that works without a jump only if the turn is 90 degrees (at 45 an X would snap).
  • Clock and sun use new Date(Date.now()) rather than new Date(): so they follow the bench’s time even in previews recorded frame by frame.
  • The wave goes to the corner farthest from the knob, not to the diagonal: the knob sits in a corner and a shorter radius would leave a wedge of the old colour.

Libraries

GSAP 3.15.0, Geist Mono (font variabile) 5.3.0.

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

Testing

Tested on 14 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