Kinetic type JS behaviour

Word fill on scroll

A narrative paragraph whose words turn on one by one — from dim grey to full ink — as reading advances; a sticky percentage marker and a hairline rail report the progress live beside the text.

Documentation

Real scenarios

The component as it is used in a product — not a specimen grid.

Reading that lights its own way

Every word carries a share of the reading progress: as the pane scrolls, colour climbs the paragraph exactly as fast as the reader — dim grey ahead of them, full ink behind. The sticky marker keeps the percentage and the rail honest, and one rAF-throttled handler does all the work.

Lumen Studio tells its product story like this: the idea was sketched in Copenhagen, the first prototype was printed in Osaka, and feedback from forty thousand users — Toronto to São Paulo — polished every edge. The shared library landed first, then the motion tokens, and yesterday the public release went out to every team. Keep scrolling to read on; every word lights up exactly as you reach it, then the closing line hands you the launch date.

--lit per word · scrollTop ÷ (scrollHeight − clientHeight) · rAF-throttled · instant under reduced motion

Important props

Important props
Prop Type Default What it does
--lit 0 → 1 'per word' Each word’s share of the progress; colour interpolates between dim grey and full ink, so the frontier word lands half-lit.
progress 0–100% 'scrollTop ÷ (scrollHeight − clientHeight)' Reading progress straight from the text’s own scroll position; the same number drives the rail and the marker.
marker sticky 'rail' The percentage marker and its vertical rail stay put while the page scrolls, so half-finished reading is always framed.
reduced-motion behaviour 'instant' No transition; word lighting snaps straight to the scroll position with no smoothing.

Snippet

{{-- resources/views/demos/components/kinetic/word-fill-scroll.blade.php --}}
<div class="wfs" x-data="{
        pct: 0, raf: 0,
        measure() {
            const el = this.$refs.page;
            const p = el.scrollTop / Math.max(1, el.scrollHeight - el.clientHeight);
            this.pct = Math.round(p * 100);
            const lit = p * this.$refs.text.querySelectorAll('.wfs-w').length;
            this.$refs.text.querySelectorAll('.wfs-w').forEach((w, i) =>
                w.style.setProperty('--lit', Math.max(0, Math.min(1, lit - i)).toFixed(3)));
        },
        onScroll() {
            cancelAnimationFrame(this.raf);
            this.raf = requestAnimationFrame(() => this.measure());
        },
        init() { this.measure(); },
        destroy() { cancelAnimationFrame(this.raf); },
    }">
    <aside class="wfs-rail">
        <b class="wfs-pct" x-text="pct + '%'"></b>
        <i class="wfs-track"><b class="wfs-fill" x-bind:style="`block-size:${pct}%`"></b></i>
    </aside>
    <div class="wfs-page" x-ref="page" x-on:scroll.passive="onScroll">
        <p class="wfs-text" x-ref="text">
            @foreach (['Lumen', 'Studio', 'tells', 'its', 'product', 'story', 'like', 'this'] as $w)
                <span class="wfs-w">{{ $w }}</span>
            @endforeach
        </p>
    </div>
</div>

<style>
.wfs { display: grid; grid-template-columns: 3rem 1fr; gap: 1rem; }
.wfs-page { block-size: 16rem; overflow-y: auto; border: 1px solid #e7e5e4;
            border-radius: 1rem; padding: 1.25rem; line-height: 1.9; }
.wfs-w { color: color-mix(in oklab, #1c1917 calc(var(--lit, 0) * 100%), #a8a29e);
         transition: color .18s linear; }
.wfs-rail { position: sticky; inset-block-start: 1rem; }
.wfs-track { display: block; inline-size: 3px; block-size: 8rem; background: #e7e5e4; }
.wfs-fill { display: block; inline-size: 100%; background: #7c3aed; }
</style>
// app/Pages/ReleaseNotes.jsx — Inertia (React) page; renders the React
// snippet below unchanged, with Inertia's Link wired into the provider.
import { Link } from '@inertiajs/react';
import { NabuXUIProvider } from '@nabuxai/ui-react';
import WordFillScroll from '@/components/WordFillScroll';

export default function ReleaseNotes() {
  return (
    <NabuXUIProvider locale="en" linkComponent={Link}>
      <main className="nx-page">
        <WordFillScroll />
      </main>
    </NabuXUIProvider>
  );
}
// WordFillScroll.jsx — words light up as the reader scrolls
import { useRef, useState } from 'react';
import '@nabuxai/ui-core/css';

const STORY = 'Lumen Studio tells its product story like this: the idea was sketched in Copenhagen, ' +
  'the first prototype was printed in Osaka, and feedback from forty thousand users polished every edge. ' +
  'Today the release ships worldwide.';

export default function WordFillScroll() {
  const page = useRef(null);
  const [pct, setPct] = useState(0);
  const words = STORY.split(' ');

  const onScroll = () => {
    const el = page.current;
    const p = el.scrollTop / Math.max(1, el.scrollHeight - el.clientHeight);
    setPct(Math.round(p * 100));
    const lit = p * words.length; // words ahead of the reader stay dim
    el.querySelectorAll('.wfs-w').forEach((w, i) =>
      w.style.setProperty('--lit', Math.max(0, Math.min(1, lit - i)).toFixed(3)));
  };

  return (
    <>
      <style>{`
        .wfs { display: grid; grid-template-columns: 3rem 1fr; gap: 1rem; max-inline-size: 44rem; }
        .wfs-page { block-size: 16rem; overflow-y: auto; padding: 1.25rem; border: 1px solid #e7e5e4;
                    border-radius: 1rem; font: 400 1rem/1.9 'IBM Plex Sans', sans-serif; }
        .wfs-w { color: color-mix(in oklab, #1c1917 calc(var(--lit, 0) * 100%), #a8a29e);
                 transition: color .18s linear; }
        .wfs-rail { position: sticky; inset-block-start: 1rem; display: grid; gap: .5rem; justify-items: center; }
        .wfs-pct { font-variant-numeric: tabular-nums; }
        .wfs-track { display: block; inline-size: 3px; block-size: 8rem; background: #e7e5e4; }
        .wfs-fill { display: block; inline-size: 100%; background: #7c3aed; }
      `}</style>
      <div className="wfs">
        <aside className="wfs-rail">
          <b className="wfs-pct">{pct}%</b>
          <i className="wfs-track"><b className="wfs-fill" style={{ blockSize: pct + '%' }} /></i>
        </aside>
        <div className="wfs-page" ref={page} onScroll={onScroll}>
          <p style={{ margin: 0 }}>
            {words.map((w, i) => <span className="wfs-w" key={i}>{w}{' '}</span>)}
          </p>
        </div>
      </div>
    </>
  );
}
<!-- WordFillScroll.vue — words light up as the reader scrolls -->
<script setup>
import { ref } from 'vue';
import '@nabuxai/ui-core/css';

const STORY = 'Lumen Studio tells its product story like this: the idea was sketched in Copenhagen, ' +
  'the first prototype was printed in Osaka, and feedback from forty thousand users polished every edge. ' +
  'Today the release ships worldwide.';
const words = STORY.split(' ');
const page = ref(null);
const pct = ref(0);

function onScroll() {
  const el = page.value;
  const p = el.scrollTop / Math.max(1, el.scrollHeight - el.clientHeight);
  pct.value = Math.round(p * 100);
  const lit = p * words.length; // words ahead of the reader stay dim
  el.querySelectorAll('.wfs-w').forEach((w, i) =>
    w.style.setProperty('--lit', Math.max(0, Math.min(1, lit - i)).toFixed(3)));
}
</script>

<template>
  <div class="wfs">
    <aside class="wfs-rail">
      <b class="wfs-pct">{{ pct }}%</b>
      <i class="wfs-track"><b class="wfs-fill" :style="{ blockSize: pct + '%' }"></b></i>
    </aside>
    <div class="wfs-page" ref="page" @scroll.passive="onScroll">
      <p class="wfs-text" style="margin: 0">
        <span v-for="(w, i) in words" :key="i" class="wfs-w">{{ w }} </span>
      </p>
    </div>
  </div>
</template>

<style scoped>
.wfs { display: grid; grid-template-columns: 3rem 1fr; gap: 1rem; max-inline-size: 44rem; }
.wfs-page { block-size: 16rem; overflow-y: auto; padding: 1.25rem; border: 1px solid #e7e5e4;
            border-radius: 1rem; font: 400 1rem/1.9 'IBM Plex Sans', sans-serif; }
.wfs-w { color: color-mix(in oklab, #1c1917 calc(var(--lit, 0) * 100%), #a8a29e);
         transition: color .18s linear; }
.wfs-rail { position: sticky; inset-block-start: 1rem; display: grid; gap: .5rem; justify-items: center; }
.wfs-pct { font-variant-numeric: tabular-nums; }
.wfs-track { display: block; inline-size: 3px; block-size: 8rem; background: #e7e5e4; }
.wfs-fill { display: block; inline-size: 100%; background: #7c3aed; }
</style>
<!-- WordFillScroll.svelte — words light up as the reader scrolls -->
<script>
  import '@nabuxai/ui-core/css';
  const STORY = 'Lumen Studio tells its product story like this: the idea was sketched in Copenhagen, ' +
    'the first prototype was printed in Osaka, and feedback from forty thousand users polished every edge. ' +
    'Today the release ships worldwide.';
  const words = STORY.split(' ');
  let page;
  let pct = $state(0);

  function onScroll() {
    const p = page.scrollTop / Math.max(1, page.scrollHeight - page.clientHeight);
    pct = Math.round(p * 100);
    const lit = p * words.length; // words ahead of the reader stay dim
    page.querySelectorAll('.wfs-w').forEach((w, i) =>
      w.style.setProperty('--lit', Math.max(0, Math.min(1, lit - i)).toFixed(3)));
  }
</script>

<div class="wfs">
  <aside class="wfs-rail">
    <b class="wfs-pct">{pct}%</b>
    <i class="wfs-track"><b class="wfs-fill" style={`block-size:${pct}%`}></b></i>
  </aside>
  <div class="wfs-page" bind:this={page} onscroll={onScroll}>
    <p class="wfs-text" style="margin: 0">
      {#each words as w, i (w + i)}<span class="wfs-w">{w} </span>{/each}
    </p>
  </div>
</div>

<style>
  .wfs { display: grid; grid-template-columns: 3rem 1fr; gap: 1rem; max-inline-size: 44rem; }
  .wfs-page { block-size: 16rem; overflow-y: auto; padding: 1.25rem; border: 1px solid #e7e5e4;
              border-radius: 1rem; font: 400 1rem/1.9 'IBM Plex Sans', sans-serif; }
  .wfs-w { color: color-mix(in oklab, #1c1917 calc(var(--lit, 0) * 100%), #a8a29e);
           transition: color .18s linear; }
  .wfs-rail { position: sticky; inset-block-start: 1rem; display: grid; gap: .5rem; justify-items: center; }
  .wfs-pct { font-variant-numeric: tabular-nums; }
  .wfs-track { display: block; inline-size: 3px; block-size: 8rem; background: #e7e5e4; }
  .wfs-fill { display: block; inline-size: 100%; background: #7c3aed; }
</style>