11 CSS Page Transitions11 / 11

CSS + JSMIT licensed

Paint Brush Stroke

A wide organic bezier brushstroke sweeps across the viewport — overlapping waves with ink texture and rough-edge noise. The accent colour shifts per page. A contemporary art gallery.

Published

Live Demo
Try it

This is a full-page demo — interact inside the frame above, or open it in the playground for the full-screen experience.

The code

<canvas id="strokeCanvas"></canvas>

<div class="pages">

  <div class="page active" id="p0">
    <div class="p0-left">
      <div class="gallery-wordmark">Volta — Contemporary Art</div>
      <div class="p0-hero">
        <div class="exhibition-tag">Current Exhibition</div>
        <h1 class="p0-title">Surface<br>/<br><span class="accent">Pressure</span></h1>
        <p class="p0-sub">New works by Noa Svensson. Painting as excavation — as the removal of what was always already there.</p>
        <button class="stroke-btn" data-next="1"><span>See all exhibitions</span></button>
      </div>
      <div class="p0-footer-info">
        <div class="on-view-badge">On View</div>
        <div class="p0-dates">12 September — 18 November 2025</div>
      </div>
    </div>
    <div class="p0-right">
      <div class="painting">
        <div class="paint-top">
          <div class="paint-shape"></div>
          <div class="paint-shape2"></div>
        </div>
        <div class="paint-bottom">
          <div class="paint-bl"></div>
          <div class="paint-br"></div>
        </div>
      </div>
      <div class="painting-caption">
        <div class="cap-title">Surface / Pressure No. 7</div>
        <div class="cap-dim">Oil on linen · 240 × 180 cm</div>
      </div>
    </div>
  </div>

  <div class="page" id="p1">
    <div class="p1-top">
      <h2 class="p1-title">Exhibitions</h2>
      <div class="p1-count">Current + Upcoming</div>
    </div>
    <div class="exh-list">
      <div class="exh-row">
        <div class="exh-cell"><span class="exh-num">01</span></div>
        <div class="exh-cell"><div><div class="exh-title">Surface / Pressure</div><div class="exh-artist">Noa Svensson</div></div></div>
        <div class="exh-cell"><span class="exh-dates">12 Sep — 18 Nov 2025</span></div>
        <div class="exh-cell"><span class="exh-status status-now">Now On</span></div>
      </div>
      <div class="exh-row">
        <div class="exh-cell"><span class="exh-num">02</span></div>
        <div class="exh-cell"><div><div class="exh-title">Weight of Light</div><div class="exh-artist">Tomás Erdős</div></div></div>
        <div class="exh-cell"><span class="exh-dates">28 Nov — 14 Feb 2026</span></div>
        <div class="exh-cell"><span class="exh-status status-up">Upcoming</span></div>
      </div>
      <div class="exh-row">
        <div class="exh-cell"><span class="exh-num">03</span></div>
        <div class="exh-cell"><div><div class="exh-title">Groundwork</div><div class="exh-artist">Amara Osei</div></div></div>
        <div class="exh-cell"><span class="exh-dates">22 Feb — 10 May 2026</span></div>
        <div class="exh-cell"><span class="exh-status status-up">Upcoming</span></div>
      </div>
      <div class="exh-row">
        <div class="exh-cell"><span class="exh-num">04</span></div>
        <div class="exh-cell"><div><div class="exh-title">Interval</div><div class="exh-artist">Group Exhibition</div></div></div>
        <div class="exh-cell"><span class="exh-dates">1 Jun — 30 Aug 2025</span></div>
        <div class="exh-cell"><span class="exh-status status-past">Closed</span></div>
      </div>
      <div class="exh-row">
        <div class="exh-cell"><span class="exh-num">05</span></div>
        <div class="exh-cell"><div><div class="exh-title">After the Voice</div><div class="exh-artist">Priya Krishnaswamy</div></div></div>
        <div class="exh-cell"><span class="exh-dates">15 Mar — 28 May 2025</span></div>
        <div class="exh-cell"><span class="exh-status status-past">Closed</span></div>
      </div>
    </div>
  </div>

  <div class="page" id="p2">
    <div class="p2-main">
      <div>
        <div class="p2-eyebrow">Featured Artist</div>
        <h2 class="p2-artist-name">Noa<br><span class="line2">Svensson</span></h2>
        <div class="p2-born">b. 1982 · Stockholm · Lives and works in Berlin and Oslo</div>
        <p class="p2-bio">Svensson's paintings begin with dense, opaque surfaces which she systematically removes — scraping, sanding, and dissolving layers until something she cannot account for emerges. She considers the work finished when she no longer recognises her own intentions in it.</p>
      </div>
      <div class="p2-stats">
        <div class="p2-stat"><div class="p2-stat-num">42</div><div class="p2-stat-label">Solo exhibitions</div></div>
        <div class="p2-stat"><div class="p2-stat-num">18</div><div class="p2-stat-label">Museums collecting</div></div>
        <div class="p2-stat"><div class="p2-stat-num">2009</div><div class="p2-stat-label">First solo show</div></div>
      </div>
    </div>
    <div class="p2-right">
      <div class="p2-works-label">Selected Works</div>
      <div class="work-item"><div class="work-year">2025</div><div class="work-title">Surface / Pressure No. 7</div><div class="work-medium">Oil on linen · 240 × 180 cm</div></div>
      <div class="work-item"><div class="work-year">2024</div><div class="work-title">Still Counting</div><div class="work-medium">Mixed media on panel · 120 × 90 cm</div></div>
      <div class="work-item"><div class="work-year">2023</div><div class="work-title">The Weight of It</div><div class="work-medium">Oil, sand, wax on canvas · 300 × 200 cm</div></div>
      <div class="work-item"><div class="work-year">2022</div><div class="work-title">Revision (IV)</div><div class="work-medium">Graphite, oil on board · 80 × 60 cm</div></div>
      <div class="work-item"><div class="work-year">2021</div><div class="work-title">Groundlessness</div><div class="work-medium">Oil on aluminium · 200 × 160 cm</div></div>
    </div>
  </div>

  <div class="page" id="p3">
    <div class="p3-bg-text">VOLTA</div>
    <div class="p3-content">
      <div class="p3-left">
        <h2 class="p3-big">COME<br>SEE<br>ART</h2>
        <p class="p3-tagline">We don't believe art needs to be explained before it can be felt. Come with an open hour and no particular expectations.</p>
      </div>
      <div class="p3-right">
        <div class="visit-row"><div class="visit-key">Location</div><div class="visit-val">Torstraße 88, Berlin</div></div>
        <div class="visit-row"><div class="visit-key">Tues — Friday</div><div class="visit-val">11am — 7pm</div></div>
        <div class="visit-row"><div class="visit-key">Saturday</div><div class="visit-val">10am — 6pm</div></div>
        <div class="visit-row"><div class="visit-key">Sunday — Monday</div><div class="visit-val">Closed</div></div>
        <div class="visit-row"><div class="visit-key">Admission</div><div class="visit-val">Free, always</div></div>
        <div class="visit-row"><div class="visit-key">Contact</div><div class="visit-val">hello@volta.gallery</div></div>
      </div>
    </div>
  </div>

</div>

<!-- Nav -->
<div class="stroke-nav" id="strokeNav">
  <button class="stroke-nav-item active" data-i="0"><span>Home</span><div class="nav-stroke-line"></div></button>
  <button class="stroke-nav-item" data-i="1"><span>Exhibitions</span><div class="nav-stroke-line"></div></button>
  <button class="stroke-nav-item" data-i="2"><span>Artist</span><div class="nav-stroke-line"></div></button>
  <button class="stroke-nav-item" data-i="3"><span>Visit</span><div class="nav-stroke-line"></div></button>
</div>
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --white: #fafaf8;
  --off: #f0eeea;
  --ink: #0a0a0a;
  --dim: rgba(10,10,10,0.35);
  --faint: rgba(10,10,10,0.06);
  --accent: #e84030;
}

html,
body {
  height: 100%;
  overflow: hidden;
  background: var(--white);
  font-family: 'Hanken Grotesk',sans-serif;
  color: var(--ink);
}
/* Pages */

.pages {
  position: fixed;
  inset: 0;
}

.page {
  position: absolute;
  inset: 0;
  visibility: hidden;
  pointer-events: none;
}

.page.active {
  visibility: visible;
  pointer-events: auto;
}
/* Stroke canvas */

#strokeCanvas {
  position: fixed;
  inset: 0;
  z-index: 700;
  pointer-events: none;
}
/* PAGE 0 — GALLERY HOME */

#p0 {
  background: var(--white);
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.p0-left {
  padding: 64px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border-right: 1px solid var(--faint);
}

.gallery-wordmark {
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink);
}

.p0-hero {
  display: flex;
  flex-direction: column;
}

.exhibition-tag {
  font-size: 9px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--dim);
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.exhibition-tag::before {
  content: '';
  width: 20px;
  height: 2px;
  background: var(--accent);
  flex-shrink: 0;
}

.p0-title {
  font-size: clamp(48px,7.5vw,100px);
  font-weight: 900;
  line-height: 0.9;
  letter-spacing: -0.05em;
  color: var(--ink);
  margin-bottom: 20px;
}

.p0-title .accent {
  color: var(--accent);
}

.p0-sub {
  font-size: 15px;
  line-height: 1.7;
  font-weight: 200;
  font-style: italic;
  color: var(--dim);
  max-width: 360px;
  margin-bottom: 40px;
}

.stroke-btn {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  background: var(--ink);
  color: var(--white);
  padding: 16px 36px;
  border: none;
  font-family: 'Hanken Grotesk',sans-serif;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
  width: fit-content;
  position: relative;
  overflow: hidden;
  transition: transform .15s;
}

.stroke-btn:hover {
  transform: translateY(-2px);
}

.stroke-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform .3s cubic-bezier(0.76,0,0.24,1);
}

.stroke-btn:hover::before {
  transform: scaleX(1);
}

.stroke-btn span {
  position: relative;
  z-index: 1;
}

.p0-footer-info {
  display: flex;
  align-items: center;
  gap: 16px;
}

.on-view-badge {
  font-size: 8px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  background: var(--accent);
  color: var(--white);
  padding: 4px 12px;
  font-weight: 700;
}

.p0-dates {
  font-size: 10px;
  letter-spacing: 0.06em;
  color: var(--dim);
  font-style: italic;
}

.p0-right {
  position: relative;
  overflow: hidden;
  background: var(--off);
  display: flex;
  align-items: center;
  justify-content: center;
}
/* Abstract painting: rect compositions */

.painting {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-rows: 60% 40%;
  gap: 2px;
  padding: 2px;
}

.paint-top {
  background: linear-gradient(135deg,#1a1a2e,#0d0d1a);
  position: relative;
  overflow: hidden;
}

.paint-bottom {
  display: grid;
  grid-template-columns: 60% 40%;
  gap: 2px;
}

.paint-bl {
  background: var(--accent);
}

.paint-br {
  background: var(--off);
}
/* White shape overlay */

.paint-shape {
  position: absolute;
  width: 180px;
  height: 180px;
  border-radius: 50% 10% 50% 10%;
  background: rgba(255,255,255,0.07);
  top: 30%;
  left: 20%;
}

.paint-shape2 {
  position: absolute;
  width: 80px;
  height: 120px;
  background: rgba(255,255,255,0.04);
  bottom: 10%;
  right: 15%;
  border-radius: 50% 50% 0 0;
}

.painting-caption {
  position: absolute;
  bottom: 20px;
  left: 24px;
  right: 24px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  z-index: 2;
}

.cap-title {
  font-size: 12px;
  font-style: italic;
  font-weight: 200;
  color: rgba(255,255,255,0.5);
}

.cap-dim {
  font-size: 9px;
  letter-spacing: 0.12em;
  color: rgba(255,255,255,0.25);
}
/* PAGE 1 — EXHIBITIONS */

#p1 {
  background: var(--white);
  padding: 64px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.p1-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 52px;
  padding-bottom: 24px;
  border-bottom: 2px solid var(--ink);
}

.p1-title {
  font-size: clamp(48px,8vw,100px);
  font-weight: 900;
  letter-spacing: -0.05em;
  line-height: 0.9;
  color: var(--ink);
}

.p1-count {
  font-size: 9px;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: var(--dim);
  font-weight: 300;
  padding-bottom: 8px;
}

.exh-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.exh-row {
  display: grid;
  grid-template-columns: 80px 1fr 200px 120px;
  border-bottom: 1px solid var(--faint);
  transition: background .15s;
  cursor: pointer;
}

.exh-row:hover {
  background: rgba(10,10,10,0.02);
}

.exh-cell {
  padding: 24px 20px;
  border-right: 1px solid var(--faint);
  display: flex;
  align-items: center;
}

.exh-cell:last-child {
  border-right: none;
}

.exh-num {
  font-size: 9px;
  color: var(--dim);
  letter-spacing: 0.1em;
  font-weight: 300;
}

.exh-title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.exh-artist {
  font-size: 11px;
  font-weight: 200;
  font-style: italic;
  color: var(--dim);
  margin-top: 4px;
}

.exh-dates {
  font-size: 10px;
  font-weight: 300;
  font-style: italic;
  color: var(--dim);
  letter-spacing: 0.04em;
}

.exh-status {
  font-size: 8px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  padding: 4px 12px;
  font-weight: 700;
}

.status-now {
  background: var(--accent);
  color: var(--white);
}

.status-up {
  background: var(--ink);
  color: var(--white);
}

.status-past {
  color: var(--dim);
  border: 1px solid var(--faint);
}
/* PAGE 2 — ARTIST */

#p2 {
  background: var(--ink);
  color: var(--white);
  display: grid;
  grid-template-columns: 1fr 480px;
}

.p2-main {
  padding: 64px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border-right: 1px solid rgba(255,255,255,0.05);
}

.p2-eyebrow {
  font-size: 9px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.3);
  margin-bottom: 28px;
}

.p2-artist-name {
  font-size: clamp(48px,7vw,96px);
  font-weight: 900;
  line-height: 0.9;
  letter-spacing: -0.04em;
  color: var(--white);
  margin-bottom: 20px;
}

.p2-artist-name .line2 {
  display: block;
  color: var(--accent);
}

.p2-born {
  font-size: 11px;
  font-style: italic;
  color: rgba(255,255,255,0.3);
  margin-bottom: 40px;
  letter-spacing: 0.06em;
}

.p2-bio {
  font-size: 14px;
  line-height: 1.85;
  font-weight: 200;
  color: rgba(255,255,255,0.55);
  max-width: 480px;
  font-style: italic;
}

.p2-stats {
  display: flex;
  gap: 40px;
  padding-top: 32px;
  border-top: 1px solid rgba(255,255,255,0.06);
}

.p2-stat {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.p2-stat-num {
  font-size: 36px;
  font-weight: 900;
  letter-spacing: -0.04em;
  color: var(--white);
}

.p2-stat-label {
  font-size: 9px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.25);
  font-weight: 300;
}

.p2-right {
  padding: 64px 56px;
  background: #111;
  display: flex;
  flex-direction: column;
  gap: 0;
  overflow-y: auto;
}

.p2-works-label {
  font-size: 8px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.2);
  margin-bottom: 28px;
}

.work-item {
  padding: 20px 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  display: flex;
  flex-direction: column;
  gap: 6px;
  cursor: pointer;
  transition: opacity .2s;
}

.work-item:hover {
  opacity: 0.7;
}

.work-year {
  font-size: 9px;
  letter-spacing: 0.15em;
  color: var(--accent);
  font-weight: 700;
}

.work-title {
  font-size: 14px;
  font-style: italic;
  color: rgba(255,255,255,0.75);
}

.work-medium {
  font-size: 10px;
  letter-spacing: 0.06em;
  color: rgba(255,255,255,0.3);
  font-weight: 200;
}
/* PAGE 3 — VISIT */

#p3 {
  background: var(--accent);
  color: var(--white);
  display: flex;
  align-items: flex-end;
  padding: 64px;
  position: relative;
  overflow: hidden;
}

.p3-bg-text {
  position: absolute;
  font-size: 25vw;
  font-weight: 900;
  color: rgba(0,0,0,0.08);
  line-height: 1;
  letter-spacing: -0.06em;
  top: 50%;
  left: 50%;
  transform: translate(-45%,-55%);
  text-transform: uppercase;
  pointer-events: none;
  user-select: none;
}

.p3-content {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 80px;
  width: 100%;
}

.p3-left {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.p3-big {
  font-size: clamp(48px,9vw,120px);
  font-weight: 900;
  line-height: 0.9;
  letter-spacing: -0.05em;
  color: var(--white);
  margin-bottom: 24px;
}

.p3-tagline {
  font-size: 14px;
  line-height: 1.7;
  font-weight: 200;
  font-style: italic;
  color: rgba(255,255,255,0.7);
  max-width: 400px;
}

.p3-right {
  display: flex;
  flex-direction: column;
  gap: 0;
  justify-content: flex-end;
}

.visit-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 16px 0;
  border-bottom: 1px solid rgba(255,255,255,0.15);
}

.visit-key {
  font-size: 9px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  font-weight: 700;
  color: rgba(255,255,255,0.6);
}

.visit-val {
  font-size: 13px;
  font-style: italic;
  color: var(--white);
  font-weight: 300;
}
/* Stroke nav */

.stroke-nav {
  position: fixed;
  top: 40px;
  right: 48px;
  z-index: 800;
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-end;
}

.stroke-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px 0;
  font-family: 'Hanken Grotesk',sans-serif;
  font-size: 8px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: rgba(10,10,10,0.2);
  transition: color .2s;
}

.stroke-nav-item:hover {
  color: rgba(10,10,10,0.5);
}

.stroke-nav-item.active {
  color: var(--ink);
}

.nav-stroke-line {
  width: 20px;
  height: 2px;
  background: currentColor;
  transition: width .35s cubic-bezier(0.4,0,0.2,1);
}

.stroke-nav-item.active .nav-stroke-line {
  width: 40px;
}

.stroke-nav-item:hover .nav-stroke-line {
  width: 32px;
}

@media (max-width: 768px) {
  #p0,
    #p2 {
    grid-template-columns: 1fr;
  }

  .p0-right,
    .p2-right {
    display: none;
  }

  .p0-left,
    .p2-main {
    padding: 40px 28px;
  }

  #p1 {
    padding: 40px 28px;
  }

  .exh-row {
    grid-template-columns: 1fr 100px;
  }

  .exh-num,
    .exh-dates {
    display: none;
  }

  #p3 {
    padding: 40px 28px;
  }

  .p3-content {
    grid-template-columns: 1fr;
    gap: 32px;
  }

  .stroke-nav {
    top: auto;
    right: 20px;
    bottom: 20px;
  }
}
const canvas=document.getElementById('strokeCanvas');
const ctx=canvas.getContext('2d');
const pages=document.querySelectorAll('.page');
const navItems=document.querySelectorAll('.stroke-nav-item');
const nav=document.getElementById('strokeNav');
let cur=0,busy=false;

function resize(){canvas.width=window.innerWidth;canvas.height=window.innerHeight;}
resize();window.addEventListener('resize',resize);

function buildStrokePath(ctx,W,H,progress){
  const midY=H*0.5;
  const variance=H*0.18;

  ctx.beginPath();

  const waves=5;
  for(let w=0;w<waves;w++){
    const yOff=(w/(waves-1)-0.5)*variance*2;
    const cp1x=W*0.25,cp1y=midY+yOff+(Math.sin(w)*variance*0.3);
    const cp2x=W*0.65,cp2y=midY-yOff+(Math.cos(w)*variance*0.25);
    const ex=W*progress*1.05,ey=midY+yOff*0.5;

    if(w===0){
      ctx.moveTo(-20,midY-variance);
    }

    ctx.bezierCurveTo(
      cp1x,cp1y,
      cp2x,cp2y,
      Math.min(ex,W+20),ey
    );
  }

  for(let w=waves-1;w>=0;w--){
    const yOff=(w/(waves-1)-0.5)*variance*2;
    const cp1x=W*0.65,cp1y=midY-yOff+variance*0.3;
    const cp2x=W*0.25,cp2y=midY+yOff-variance*0.2;
    ctx.bezierCurveTo(
      Math.min(W*progress,W+20)+20,midY+yOff*0.5+variance*0.1,
      cp1x,cp1y,
      cp2x,cp2y
    );
  }

  ctx.closePath();
}

const strokeColors=['#0a0a0a','#0a0a0a','#fafaf8','#e84030'];

function strokeTransition(color,mid,done){
  let progress=0;
  const dur=50;
  const W=canvas.width,H=canvas.height;

  let midDone=false;

  function draw(){
    ctx.clearRect(0,0,W,H);
    const p=progress/dur;
    const ep=p<0.5?2*p*p:1-Math.pow(-2*p+2,2)/2;

    ctx.save();
    buildStrokePath(ctx,W,H,ep*1.05);

    const g=ctx.createLinearGradient(0,H*0.3,0,H*0.7);
    g.addColorStop(0,color);
    g.addColorStop(0.3,color);
    g.addColorStop(0.7,color);
    g.addColorStop(1,color);
    ctx.fillStyle=g;
    ctx.fill();

    ctx.globalCompositeOperation='destination-out';
    for(let i=0;i<8;i++){
      const noiseY=H*0.5+(Math.sin(i*2.7+progress*0.1)*H*0.08);
      const noiseX=Math.random()*W*ep;
      const r=Math.random()*30+10;
      ctx.beginPath();
      ctx.arc(noiseX,noiseY,r,0,Math.PI*2);
      ctx.fillStyle='rgba(0,0,0,0.06)';
      ctx.fill();
    }
    ctx.globalCompositeOperation='source-over';
    ctx.restore();

    if(ep>0.48&&!midDone){midDone=true;mid&&mid();}
    progress++;

    if(progress<=dur){
      requestAnimationFrame(draw);
    }else{
      let alpha=1;
      function fadeOut(){
        ctx.clearRect(0,0,W,H);
        ctx.save();
        buildStrokePath(ctx,W,H,1.05);
        ctx.fillStyle=color;
        ctx.globalAlpha=alpha;
        ctx.fill();
        ctx.globalAlpha=1;
        ctx.restore();
        alpha-=0.12;
        if(alpha>0) requestAnimationFrame(fadeOut);
        else{ctx.clearRect(0,0,W,H);done&&done();}
      }
      requestAnimationFrame(fadeOut);
    }
  }
  requestAnimationFrame(draw);
}

function goTo(n){
  if(busy||n===cur)return;
  busy=true;
  const prev=cur;cur=n;
  navItems.forEach((it,i)=>it.classList.toggle('active',i===cur));

  nav.style.color=cur===2?'white':'';

  strokeTransition(strokeColors[cur],
    ()=>{
      pages[prev].classList.remove('active');
      pages[cur].classList.add('active');
    },
    ()=>{busy=false;}
  );
}

navItems.forEach(it=>it.addEventListener('click',()=>goTo(+it.dataset.i)));
document.querySelectorAll('[data-next]').forEach(b=>b.addEventListener('click',()=>goTo(+b.dataset.next)));

let wt=0;
window.addEventListener('wheel',e=>{
  const now=Date.now();if(now-wt<1200)return;wt=now;
  goTo(Math.max(0,Math.min(3,cur+(e.deltaY>0?1:-1))));
},{passive:true});
document.addEventListener('keydown',e=>{
  if(e.key==='ArrowRight')goTo(Math.min(3,cur+1));
  if(e.key==='ArrowLeft')goTo(Math.max(0,cur-1));
});
Paste this into ChatGPT, Claude, Cursor, or any coding assistant. The block below is pre-framed with everything the AI needs to integrate this demo into your project — markup, styles, scoping notes, and the source URL. Hit Copy and paste straight into your chat.
Here's a working CSS Page Transition from CodeFronts. Use it as-is or adapt to your framework. All classes are scoped under a unique prefix so the code won't collide with your existing styles. MIT licensed.
Demo: Paint Brush Stroke
Source: https://codefronts.com/motion/css-page-transitions/paint-brush-stroke/

A wide organic bezier brushstroke sweeps across the viewport — overlapping waves with ink texture and rough-edge noise. The accent colour shifts per page. A contemporary art gallery.
## HTML
```html
<canvas id="strokeCanvas"></canvas>

<div class="pages">

  <div class="page active" id="p0">
    <div class="p0-left">
      <div class="gallery-wordmark">Volta — Contemporary Art</div>
      <div class="p0-hero">
        <div class="exhibition-tag">Current Exhibition</div>
        <h1 class="p0-title">Surface<br>/<br><span class="accent">Pressure</span></h1>
        <p class="p0-sub">New works by Noa Svensson. Painting as excavation — as the removal of what was always already there.</p>
        <button class="stroke-btn" data-next="1"><span>See all exhibitions</span></button>
      </div>
      <div class="p0-footer-info">
        <div class="on-view-badge">On View</div>
        <div class="p0-dates">12 September — 18 November 2025</div>
      </div>
    </div>
    <div class="p0-right">
      <div class="painting">
        <div class="paint-top">
          <div class="paint-shape"></div>
          <div class="paint-shape2"></div>
        </div>
        <div class="paint-bottom">
          <div class="paint-bl"></div>
          <div class="paint-br"></div>
        </div>
      </div>
      <div class="painting-caption">
        <div class="cap-title">Surface / Pressure No. 7</div>
        <div class="cap-dim">Oil on linen · 240 × 180 cm</div>
      </div>
    </div>
  </div>

  <div class="page" id="p1">
    <div class="p1-top">
      <h2 class="p1-title">Exhibitions</h2>
      <div class="p1-count">Current + Upcoming</div>
    </div>
    <div class="exh-list">
      <div class="exh-row">
        <div class="exh-cell"><span class="exh-num">01</span></div>
        <div class="exh-cell"><div><div class="exh-title">Surface / Pressure</div><div class="exh-artist">Noa Svensson</div></div></div>
        <div class="exh-cell"><span class="exh-dates">12 Sep — 18 Nov 2025</span></div>
        <div class="exh-cell"><span class="exh-status status-now">Now On</span></div>
      </div>
      <div class="exh-row">
        <div class="exh-cell"><span class="exh-num">02</span></div>
        <div class="exh-cell"><div><div class="exh-title">Weight of Light</div><div class="exh-artist">Tomás Erdős</div></div></div>
        <div class="exh-cell"><span class="exh-dates">28 Nov — 14 Feb 2026</span></div>
        <div class="exh-cell"><span class="exh-status status-up">Upcoming</span></div>
      </div>
      <div class="exh-row">
        <div class="exh-cell"><span class="exh-num">03</span></div>
        <div class="exh-cell"><div><div class="exh-title">Groundwork</div><div class="exh-artist">Amara Osei</div></div></div>
        <div class="exh-cell"><span class="exh-dates">22 Feb — 10 May 2026</span></div>
        <div class="exh-cell"><span class="exh-status status-up">Upcoming</span></div>
      </div>
      <div class="exh-row">
        <div class="exh-cell"><span class="exh-num">04</span></div>
        <div class="exh-cell"><div><div class="exh-title">Interval</div><div class="exh-artist">Group Exhibition</div></div></div>
        <div class="exh-cell"><span class="exh-dates">1 Jun — 30 Aug 2025</span></div>
        <div class="exh-cell"><span class="exh-status status-past">Closed</span></div>
      </div>
      <div class="exh-row">
        <div class="exh-cell"><span class="exh-num">05</span></div>
        <div class="exh-cell"><div><div class="exh-title">After the Voice</div><div class="exh-artist">Priya Krishnaswamy</div></div></div>
        <div class="exh-cell"><span class="exh-dates">15 Mar — 28 May 2025</span></div>
        <div class="exh-cell"><span class="exh-status status-past">Closed</span></div>
      </div>
    </div>
  </div>

  <div class="page" id="p2">
    <div class="p2-main">
      <div>
        <div class="p2-eyebrow">Featured Artist</div>
        <h2 class="p2-artist-name">Noa<br><span class="line2">Svensson</span></h2>
        <div class="p2-born">b. 1982 · Stockholm · Lives and works in Berlin and Oslo</div>
        <p class="p2-bio">Svensson's paintings begin with dense, opaque surfaces which she systematically removes — scraping, sanding, and dissolving layers until something she cannot account for emerges. She considers the work finished when she no longer recognises her own intentions in it.</p>
      </div>
      <div class="p2-stats">
        <div class="p2-stat"><div class="p2-stat-num">42</div><div class="p2-stat-label">Solo exhibitions</div></div>
        <div class="p2-stat"><div class="p2-stat-num">18</div><div class="p2-stat-label">Museums collecting</div></div>
        <div class="p2-stat"><div class="p2-stat-num">2009</div><div class="p2-stat-label">First solo show</div></div>
      </div>
    </div>
    <div class="p2-right">
      <div class="p2-works-label">Selected Works</div>
      <div class="work-item"><div class="work-year">2025</div><div class="work-title">Surface / Pressure No. 7</div><div class="work-medium">Oil on linen · 240 × 180 cm</div></div>
      <div class="work-item"><div class="work-year">2024</div><div class="work-title">Still Counting</div><div class="work-medium">Mixed media on panel · 120 × 90 cm</div></div>
      <div class="work-item"><div class="work-year">2023</div><div class="work-title">The Weight of It</div><div class="work-medium">Oil, sand, wax on canvas · 300 × 200 cm</div></div>
      <div class="work-item"><div class="work-year">2022</div><div class="work-title">Revision (IV)</div><div class="work-medium">Graphite, oil on board · 80 × 60 cm</div></div>
      <div class="work-item"><div class="work-year">2021</div><div class="work-title">Groundlessness</div><div class="work-medium">Oil on aluminium · 200 × 160 cm</div></div>
    </div>
  </div>

  <div class="page" id="p3">
    <div class="p3-bg-text">VOLTA</div>
    <div class="p3-content">
      <div class="p3-left">
        <h2 class="p3-big">COME<br>SEE<br>ART</h2>
        <p class="p3-tagline">We don't believe art needs to be explained before it can be felt. Come with an open hour and no particular expectations.</p>
      </div>
      <div class="p3-right">
        <div class="visit-row"><div class="visit-key">Location</div><div class="visit-val">Torstraße 88, Berlin</div></div>
        <div class="visit-row"><div class="visit-key">Tues — Friday</div><div class="visit-val">11am — 7pm</div></div>
        <div class="visit-row"><div class="visit-key">Saturday</div><div class="visit-val">10am — 6pm</div></div>
        <div class="visit-row"><div class="visit-key">Sunday — Monday</div><div class="visit-val">Closed</div></div>
        <div class="visit-row"><div class="visit-key">Admission</div><div class="visit-val">Free, always</div></div>
        <div class="visit-row"><div class="visit-key">Contact</div><div class="visit-val">hello@volta.gallery</div></div>
      </div>
    </div>
  </div>

</div>

<!-- Nav -->
<div class="stroke-nav" id="strokeNav">
  <button class="stroke-nav-item active" data-i="0"><span>Home</span><div class="nav-stroke-line"></div></button>
  <button class="stroke-nav-item" data-i="1"><span>Exhibitions</span><div class="nav-stroke-line"></div></button>
  <button class="stroke-nav-item" data-i="2"><span>Artist</span><div class="nav-stroke-line"></div></button>
  <button class="stroke-nav-item" data-i="3"><span>Visit</span><div class="nav-stroke-line"></div></button>
</div>
```
## CSS
```css
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --white: #fafaf8;
  --off: #f0eeea;
  --ink: #0a0a0a;
  --dim: rgba(10,10,10,0.35);
  --faint: rgba(10,10,10,0.06);
  --accent: #e84030;
}

html,
body {
  height: 100%;
  overflow: hidden;
  background: var(--white);
  font-family: 'Hanken Grotesk',sans-serif;
  color: var(--ink);
}
/* Pages */

.pages {
  position: fixed;
  inset: 0;
}

.page {
  position: absolute;
  inset: 0;
  visibility: hidden;
  pointer-events: none;
}

.page.active {
  visibility: visible;
  pointer-events: auto;
}
/* Stroke canvas */

#strokeCanvas {
  position: fixed;
  inset: 0;
  z-index: 700;
  pointer-events: none;
}
/* PAGE 0 — GALLERY HOME */

#p0 {
  background: var(--white);
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.p0-left {
  padding: 64px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border-right: 1px solid var(--faint);
}

.gallery-wordmark {
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink);
}

.p0-hero {
  display: flex;
  flex-direction: column;
}

.exhibition-tag {
  font-size: 9px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--dim);
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.exhibition-tag::before {
  content: '';
  width: 20px;
  height: 2px;
  background: var(--accent);
  flex-shrink: 0;
}

.p0-title {
  font-size: clamp(48px,7.5vw,100px);
  font-weight: 900;
  line-height: 0.9;
  letter-spacing: -0.05em;
  color: var(--ink);
  margin-bottom: 20px;
}

.p0-title .accent {
  color: var(--accent);
}

.p0-sub {
  font-size: 15px;
  line-height: 1.7;
  font-weight: 200;
  font-style: italic;
  color: var(--dim);
  max-width: 360px;
  margin-bottom: 40px;
}

.stroke-btn {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  background: var(--ink);
  color: var(--white);
  padding: 16px 36px;
  border: none;
  font-family: 'Hanken Grotesk',sans-serif;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
  width: fit-content;
  position: relative;
  overflow: hidden;
  transition: transform .15s;
}

.stroke-btn:hover {
  transform: translateY(-2px);
}

.stroke-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform .3s cubic-bezier(0.76,0,0.24,1);
}

.stroke-btn:hover::before {
  transform: scaleX(1);
}

.stroke-btn span {
  position: relative;
  z-index: 1;
}

.p0-footer-info {
  display: flex;
  align-items: center;
  gap: 16px;
}

.on-view-badge {
  font-size: 8px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  background: var(--accent);
  color: var(--white);
  padding: 4px 12px;
  font-weight: 700;
}

.p0-dates {
  font-size: 10px;
  letter-spacing: 0.06em;
  color: var(--dim);
  font-style: italic;
}

.p0-right {
  position: relative;
  overflow: hidden;
  background: var(--off);
  display: flex;
  align-items: center;
  justify-content: center;
}
/* Abstract painting: rect compositions */

.painting {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-rows: 60% 40%;
  gap: 2px;
  padding: 2px;
}

.paint-top {
  background: linear-gradient(135deg,#1a1a2e,#0d0d1a);
  position: relative;
  overflow: hidden;
}

.paint-bottom {
  display: grid;
  grid-template-columns: 60% 40%;
  gap: 2px;
}

.paint-bl {
  background: var(--accent);
}

.paint-br {
  background: var(--off);
}
/* White shape overlay */

.paint-shape {
  position: absolute;
  width: 180px;
  height: 180px;
  border-radius: 50% 10% 50% 10%;
  background: rgba(255,255,255,0.07);
  top: 30%;
  left: 20%;
}

.paint-shape2 {
  position: absolute;
  width: 80px;
  height: 120px;
  background: rgba(255,255,255,0.04);
  bottom: 10%;
  right: 15%;
  border-radius: 50% 50% 0 0;
}

.painting-caption {
  position: absolute;
  bottom: 20px;
  left: 24px;
  right: 24px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  z-index: 2;
}

.cap-title {
  font-size: 12px;
  font-style: italic;
  font-weight: 200;
  color: rgba(255,255,255,0.5);
}

.cap-dim {
  font-size: 9px;
  letter-spacing: 0.12em;
  color: rgba(255,255,255,0.25);
}
/* PAGE 1 — EXHIBITIONS */

#p1 {
  background: var(--white);
  padding: 64px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.p1-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 52px;
  padding-bottom: 24px;
  border-bottom: 2px solid var(--ink);
}

.p1-title {
  font-size: clamp(48px,8vw,100px);
  font-weight: 900;
  letter-spacing: -0.05em;
  line-height: 0.9;
  color: var(--ink);
}

.p1-count {
  font-size: 9px;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: var(--dim);
  font-weight: 300;
  padding-bottom: 8px;
}

.exh-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.exh-row {
  display: grid;
  grid-template-columns: 80px 1fr 200px 120px;
  border-bottom: 1px solid var(--faint);
  transition: background .15s;
  cursor: pointer;
}

.exh-row:hover {
  background: rgba(10,10,10,0.02);
}

.exh-cell {
  padding: 24px 20px;
  border-right: 1px solid var(--faint);
  display: flex;
  align-items: center;
}

.exh-cell:last-child {
  border-right: none;
}

.exh-num {
  font-size: 9px;
  color: var(--dim);
  letter-spacing: 0.1em;
  font-weight: 300;
}

.exh-title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.exh-artist {
  font-size: 11px;
  font-weight: 200;
  font-style: italic;
  color: var(--dim);
  margin-top: 4px;
}

.exh-dates {
  font-size: 10px;
  font-weight: 300;
  font-style: italic;
  color: var(--dim);
  letter-spacing: 0.04em;
}

.exh-status {
  font-size: 8px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  padding: 4px 12px;
  font-weight: 700;
}

.status-now {
  background: var(--accent);
  color: var(--white);
}

.status-up {
  background: var(--ink);
  color: var(--white);
}

.status-past {
  color: var(--dim);
  border: 1px solid var(--faint);
}
/* PAGE 2 — ARTIST */

#p2 {
  background: var(--ink);
  color: var(--white);
  display: grid;
  grid-template-columns: 1fr 480px;
}

.p2-main {
  padding: 64px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border-right: 1px solid rgba(255,255,255,0.05);
}

.p2-eyebrow {
  font-size: 9px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.3);
  margin-bottom: 28px;
}

.p2-artist-name {
  font-size: clamp(48px,7vw,96px);
  font-weight: 900;
  line-height: 0.9;
  letter-spacing: -0.04em;
  color: var(--white);
  margin-bottom: 20px;
}

.p2-artist-name .line2 {
  display: block;
  color: var(--accent);
}

.p2-born {
  font-size: 11px;
  font-style: italic;
  color: rgba(255,255,255,0.3);
  margin-bottom: 40px;
  letter-spacing: 0.06em;
}

.p2-bio {
  font-size: 14px;
  line-height: 1.85;
  font-weight: 200;
  color: rgba(255,255,255,0.55);
  max-width: 480px;
  font-style: italic;
}

.p2-stats {
  display: flex;
  gap: 40px;
  padding-top: 32px;
  border-top: 1px solid rgba(255,255,255,0.06);
}

.p2-stat {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.p2-stat-num {
  font-size: 36px;
  font-weight: 900;
  letter-spacing: -0.04em;
  color: var(--white);
}

.p2-stat-label {
  font-size: 9px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.25);
  font-weight: 300;
}

.p2-right {
  padding: 64px 56px;
  background: #111;
  display: flex;
  flex-direction: column;
  gap: 0;
  overflow-y: auto;
}

.p2-works-label {
  font-size: 8px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.2);
  margin-bottom: 28px;
}

.work-item {
  padding: 20px 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  display: flex;
  flex-direction: column;
  gap: 6px;
  cursor: pointer;
  transition: opacity .2s;
}

.work-item:hover {
  opacity: 0.7;
}

.work-year {
  font-size: 9px;
  letter-spacing: 0.15em;
  color: var(--accent);
  font-weight: 700;
}

.work-title {
  font-size: 14px;
  font-style: italic;
  color: rgba(255,255,255,0.75);
}

.work-medium {
  font-size: 10px;
  letter-spacing: 0.06em;
  color: rgba(255,255,255,0.3);
  font-weight: 200;
}
/* PAGE 3 — VISIT */

#p3 {
  background: var(--accent);
  color: var(--white);
  display: flex;
  align-items: flex-end;
  padding: 64px;
  position: relative;
  overflow: hidden;
}

.p3-bg-text {
  position: absolute;
  font-size: 25vw;
  font-weight: 900;
  color: rgba(0,0,0,0.08);
  line-height: 1;
  letter-spacing: -0.06em;
  top: 50%;
  left: 50%;
  transform: translate(-45%,-55%);
  text-transform: uppercase;
  pointer-events: none;
  user-select: none;
}

.p3-content {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 80px;
  width: 100%;
}

.p3-left {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.p3-big {
  font-size: clamp(48px,9vw,120px);
  font-weight: 900;
  line-height: 0.9;
  letter-spacing: -0.05em;
  color: var(--white);
  margin-bottom: 24px;
}

.p3-tagline {
  font-size: 14px;
  line-height: 1.7;
  font-weight: 200;
  font-style: italic;
  color: rgba(255,255,255,0.7);
  max-width: 400px;
}

.p3-right {
  display: flex;
  flex-direction: column;
  gap: 0;
  justify-content: flex-end;
}

.visit-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 16px 0;
  border-bottom: 1px solid rgba(255,255,255,0.15);
}

.visit-key {
  font-size: 9px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  font-weight: 700;
  color: rgba(255,255,255,0.6);
}

.visit-val {
  font-size: 13px;
  font-style: italic;
  color: var(--white);
  font-weight: 300;
}
/* Stroke nav */

.stroke-nav {
  position: fixed;
  top: 40px;
  right: 48px;
  z-index: 800;
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-end;
}

.stroke-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px 0;
  font-family: 'Hanken Grotesk',sans-serif;
  font-size: 8px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: rgba(10,10,10,0.2);
  transition: color .2s;
}

.stroke-nav-item:hover {
  color: rgba(10,10,10,0.5);
}

.stroke-nav-item.active {
  color: var(--ink);
}

.nav-stroke-line {
  width: 20px;
  height: 2px;
  background: currentColor;
  transition: width .35s cubic-bezier(0.4,0,0.2,1);
}

.stroke-nav-item.active .nav-stroke-line {
  width: 40px;
}

.stroke-nav-item:hover .nav-stroke-line {
  width: 32px;
}

@media (max-width: 768px) {
  #p0,
    #p2 {
    grid-template-columns: 1fr;
  }

  .p0-right,
    .p2-right {
    display: none;
  }

  .p0-left,
    .p2-main {
    padding: 40px 28px;
  }

  #p1 {
    padding: 40px 28px;
  }

  .exh-row {
    grid-template-columns: 1fr 100px;
  }

  .exh-num,
    .exh-dates {
    display: none;
  }

  #p3 {
    padding: 40px 28px;
  }

  .p3-content {
    grid-template-columns: 1fr;
    gap: 32px;
  }

  .stroke-nav {
    top: auto;
    right: 20px;
    bottom: 20px;
  }
}
```

## JavaScript
```js
const canvas=document.getElementById('strokeCanvas');
const ctx=canvas.getContext('2d');
const pages=document.querySelectorAll('.page');
const navItems=document.querySelectorAll('.stroke-nav-item');
const nav=document.getElementById('strokeNav');
let cur=0,busy=false;

function resize(){canvas.width=window.innerWidth;canvas.height=window.innerHeight;}
resize();window.addEventListener('resize',resize);

function buildStrokePath(ctx,W,H,progress){
  const midY=H*0.5;
  const variance=H*0.18;

  ctx.beginPath();

  const waves=5;
  for(let w=0;w<waves;w++){
    const yOff=(w/(waves-1)-0.5)*variance*2;
    const cp1x=W*0.25,cp1y=midY+yOff+(Math.sin(w)*variance*0.3);
    const cp2x=W*0.65,cp2y=midY-yOff+(Math.cos(w)*variance*0.25);
    const ex=W*progress*1.05,ey=midY+yOff*0.5;

    if(w===0){
      ctx.moveTo(-20,midY-variance);
    }

    ctx.bezierCurveTo(
      cp1x,cp1y,
      cp2x,cp2y,
      Math.min(ex,W+20),ey
    );
  }

  for(let w=waves-1;w>=0;w--){
    const yOff=(w/(waves-1)-0.5)*variance*2;
    const cp1x=W*0.65,cp1y=midY-yOff+variance*0.3;
    const cp2x=W*0.25,cp2y=midY+yOff-variance*0.2;
    ctx.bezierCurveTo(
      Math.min(W*progress,W+20)+20,midY+yOff*0.5+variance*0.1,
      cp1x,cp1y,
      cp2x,cp2y
    );
  }

  ctx.closePath();
}

const strokeColors=['#0a0a0a','#0a0a0a','#fafaf8','#e84030'];

function strokeTransition(color,mid,done){
  let progress=0;
  const dur=50;
  const W=canvas.width,H=canvas.height;

  let midDone=false;

  function draw(){
    ctx.clearRect(0,0,W,H);
    const p=progress/dur;
    const ep=p<0.5?2*p*p:1-Math.pow(-2*p+2,2)/2;

    ctx.save();
    buildStrokePath(ctx,W,H,ep*1.05);

    const g=ctx.createLinearGradient(0,H*0.3,0,H*0.7);
    g.addColorStop(0,color);
    g.addColorStop(0.3,color);
    g.addColorStop(0.7,color);
    g.addColorStop(1,color);
    ctx.fillStyle=g;
    ctx.fill();

    ctx.globalCompositeOperation='destination-out';
    for(let i=0;i<8;i++){
      const noiseY=H*0.5+(Math.sin(i*2.7+progress*0.1)*H*0.08);
      const noiseX=Math.random()*W*ep;
      const r=Math.random()*30+10;
      ctx.beginPath();
      ctx.arc(noiseX,noiseY,r,0,Math.PI*2);
      ctx.fillStyle='rgba(0,0,0,0.06)';
      ctx.fill();
    }
    ctx.globalCompositeOperation='source-over';
    ctx.restore();

    if(ep>0.48&&!midDone){midDone=true;mid&&mid();}
    progress++;

    if(progress<=dur){
      requestAnimationFrame(draw);
    }else{
      let alpha=1;
      function fadeOut(){
        ctx.clearRect(0,0,W,H);
        ctx.save();
        buildStrokePath(ctx,W,H,1.05);
        ctx.fillStyle=color;
        ctx.globalAlpha=alpha;
        ctx.fill();
        ctx.globalAlpha=1;
        ctx.restore();
        alpha-=0.12;
        if(alpha>0) requestAnimationFrame(fadeOut);
        else{ctx.clearRect(0,0,W,H);done&&done();}
      }
      requestAnimationFrame(fadeOut);
    }
  }
  requestAnimationFrame(draw);
}

function goTo(n){
  if(busy||n===cur)return;
  busy=true;
  const prev=cur;cur=n;
  navItems.forEach((it,i)=>it.classList.toggle('active',i===cur));

  nav.style.color=cur===2?'white':'';

  strokeTransition(strokeColors[cur],
    ()=>{
      pages[prev].classList.remove('active');
      pages[cur].classList.add('active');
    },
    ()=>{busy=false;}
  );
}

navItems.forEach(it=>it.addEventListener('click',()=>goTo(+it.dataset.i)));
document.querySelectorAll('[data-next]').forEach(b=>b.addEventListener('click',()=>goTo(+b.dataset.next)));

let wt=0;
window.addEventListener('wheel',e=>{
  const now=Date.now();if(now-wt<1200)return;wt=now;
  goTo(Math.max(0,Math.min(3,cur+(e.deltaY>0?1:-1))));
},{passive:true});
document.addEventListener('keydown',e=>{
  if(e.key==='ArrowRight')goTo(Math.min(3,cur+1));
  if(e.key==='ArrowLeft')goTo(Math.max(0,cur-1));
});
```

Techniques used in this demo

Search CodeFronts

Loading…