Letter wave
A title whose units — letters for Latin, whole words for Persian — bob and tilt like a wave; the unit nearest the pointer leaps higher, and a slider turns the swell down or up.
Real scenarios
The component as it is used in a product — not a specimen grid.
A title that swims under the pointer
Each unit rides a travelling sine — translateY with a phase-shifted tilt — and the pointer drops a gaussian boost (σ ≈ 70px) so the nearest units leap higher. Latin units are letters; Persian units are whole words, never broken letters. The slider scales the swell from dead calm to double storm.
OCEANLINE · MARINE RESEARCH PLATFORM
sin(t · 2.2 + i · 0.55) · 10px · gaussian pointer boost · rAF parked off screen · still under reduced motion
Important props
| Prop | Type | Default | What it does |
|---|---|---|---|
| amplitude | px | '10' | The base swell; the slider drags it from zero up to twice the default. |
| phase | rad/unit | '.55' | The phase offset between units — what reads as a wave instead of a simultaneous bounce. |
| pointer-boost | gaussian | 'σ ≈ 70px' | A gaussian boost near the pointer; it decays with distance and fades out when the pointer leaves. |
| reduced-motion | behaviour | 'still' | The wave stops and the title settles flat; the rAF loop is parked off screen as well. |
Snippet
{{-- resources/views/demos/components/kinetic/letter-wave.blade.php --}}
{{-- Latin: letter level --}}
<div class="ltwv" x-data="{
units: [], raf: 0, t0: 0, io: null, mq: null, onMq: null,
mx: 0, boost: 0, amp: 1, visible: true,
frame(now) {
const t = (now - this.t0) / 1000;
this.units.forEach((u, i) => {
const near = Math.exp(-((u.x - this.mx) ** 2) / 9800) * this.boost;
const y = Math.sin(t * 2.2 + i * 0.55) * 10 * this.amp * (1 + 2 * near);
const r = Math.sin(t * 2.2 + i * 0.55 + 0.9) * 3 * this.amp * (1 + near);
u.el.style.transform = `translateY(${y.toFixed(2)}px) rotate(${r.toFixed(2)}deg)`;
});
this.raf = requestAnimationFrame((n) => this.frame(n));
},
run() {
cancelAnimationFrame(this.raf);
if (this.mq.matches || !this.visible) return;
this.raf = requestAnimationFrame((n) => this.frame(n));
},
init() {
this.t0 = performance.now();
this.units = [...this.$refs.title.querySelectorAll('.ltwv-u')].map((el) => ({ el, x: 0 }));
const place = () => this.units.forEach((u) => (u.x = u.el.getBoundingClientRect().x + u.el.offsetWidth / 2));
place(); addEventListener('resize', place);
this.mq = matchMedia('(prefers-reduced-motion: reduce)');
this.onMq = () => this.run();
this.mq.addEventListener('change', this.onMq);
this.io = new IntersectionObserver((e) => { this.visible = e[0].isIntersecting; this.run(); });
this.io.observe(this.$refs.title);
this.run();
},
destroy() {
cancelAnimationFrame(this.raf);
if (this.io) this.io.disconnect();
if (this.mq && this.onMq) this.mq.removeEventListener('change', this.onMq);
},
}"
x-on:pointermove="(mx = $event.offsetX) && (boost = 1)"
x-on:pointerleave="boost = 0">
<h2 class="ltwv-title" x-ref="title">
@foreach (str_split('MAKING WAVES') as $u)
<span class="ltwv-u">{{ $u === ' ' ? ' ' : $u }}</span>
@endforeach
</h2>
<label class="ltwv-amp">Swell <input type="range" min="0" max="2" step=".05" value="1" x-model.number="amp"></label>
</div>
<style>
.ltwv-title { display: flex; flex-wrap: wrap; font-weight: 900;
font-size: clamp(2rem, 8vw, 4rem); perspective: 500px; }
.ltwv-u { display: inline-block; will-change: transform; }
.ltwv-amp { display: flex; gap: .6rem; align-items: center; }
</style>
// app/Pages/TypeLab.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 LetterWave from '@/components/LetterWave';
export default function TypeLab() {
return (
<NabuXUIProvider locale="en" linkComponent={Link}>
<main className="nx-page">
<LetterWave />
</main>
</NabuXUIProvider>
);
}
// LetterWave.jsx — letters bob like a wave; the pointer's neighbours leap
import { useEffect, useRef, useState } from 'react';
import '@nabuxai/ui-core/css';
const TITLE = 'MAKING WAVES';
export default function LetterWave() {
const [amp, setAmp] = useState(1);
const title = useRef(null);
const ampRef = useRef(amp);
ampRef.current = amp;
const units = useRef([]);
useEffect(() => {
const el = title.current;
const mq = matchMedia('(prefers-reduced-motion: reduce)');
const t0 = performance.now();
let mx = 0, boost = 0, raf = 0, visible = true;
const measure = () => {
units.current = [...el.querySelectorAll('.ltwv-u')].map((u) => ({
el: u, x: u.getBoundingClientRect().x + u.offsetWidth / 2,
}));
};
const frame = (now) => {
const t = (now - t0) / 1000;
units.current.forEach((u, i) => {
const near = Math.exp(-((u.x - mx) ** 2) / 9800) * boost;
const y = Math.sin(t * 2.2 + i * 0.55) * 10 * ampRef.current * (1 + 2 * near);
const r = Math.sin(t * 2.2 + i * 0.55 + 0.9) * 3 * ampRef.current * (1 + near);
u.el.style.transform = `translateY(${y.toFixed(2)}px) rotate(${r.toFixed(2)}deg)`;
});
raf = requestAnimationFrame(frame);
};
const run = () => { cancelAnimationFrame(raf); if (!mq.matches && visible) raf = requestAnimationFrame(frame); };
const move = (e) => { mx = e.clientX; boost = 1; };
const leave = () => { boost = 0; };
measure();
addEventListener('resize', measure);
el.addEventListener('pointermove', move);
el.addEventListener('pointerleave', leave);
mq.addEventListener('change', run);
const io = new IntersectionObserver(([e]) => { visible = e.isIntersecting; run(); });
io.observe(el);
run();
return () => {
cancelAnimationFrame(raf); io.disconnect(); mq.removeEventListener('change', run);
removeEventListener('resize', measure);
el.removeEventListener('pointermove', move);
el.removeEventListener('pointerleave', leave);
};
}, []);
return (
<>
<style>{`
.ltwv-title { display: flex; flex-wrap: wrap; margin: 0; font: 900 clamp(2rem, 8vw, 4rem)/1.1 'IBM Plex Sans', sans-serif;
perspective: 500px; cursor: default; }
.ltwv-u { display: inline-block; will-change: transform; }
.ltwv-amp { display: flex; gap: .6rem; align-items: center; margin-block-start: 1rem; }
`}</style>
<h2 className="ltwv-title" ref={title} aria-label={TITLE}>
{TITLE.split('').map((ch, i) => (
<span className="ltwv-u" key={i} aria-hidden="true">{ch === ' ' ? '\u00A0' : ch}</span>
))}
</h2>
<label className="ltwv-amp">
Swell
<input type="range" min="0" max="2" step="0.05" value={amp}
onChange={(e) => setAmp(Number(e.target.value))} />
</label>
</>
);
}
<!-- LetterWave.vue — letters bob like a wave; the pointer's neighbours leap -->
<script setup>
import { onBeforeUnmount, onMounted, ref } from 'vue';
import '@nabuxai/ui-core/css';
const TITLE = 'MAKING WAVES';
const title = ref(null);
const amp = ref(1);
let units = [], raf = 0, io = null, t0 = 0, mx = 0, boost = 0;
const mq = matchMedia('(prefers-reduced-motion: reduce)');
function measure() {
units = [...title.value.querySelectorAll('.ltwv-u')].map((u) => ({
el: u, x: u.getBoundingClientRect().x + u.offsetWidth / 2,
}));
}
function frame(now) {
const t = (now - t0) / 1000;
units.forEach((u, i) => {
const near = Math.exp(-((u.x - mx) ** 2) / 9800) * boost;
const y = Math.sin(t * 2.2 + i * 0.55) * 10 * amp.value * (1 + 2 * near);
const r = Math.sin(t * 2.2 + i * 0.55 + 0.9) * 3 * amp.value * (1 + near);
u.el.style.transform = `translateY(${y.toFixed(2)}px) rotate(${r.toFixed(2)}deg)`;
});
raf = requestAnimationFrame(frame);
}
function run() { cancelAnimationFrame(raf); if (!mq.matches) raf = requestAnimationFrame(frame); }
onMounted(() => {
t0 = performance.now();
measure();
addEventListener('resize', measure);
mq.addEventListener('change', run);
io = new IntersectionObserver(([e]) => (e.isIntersecting ? run() : cancelAnimationFrame(raf)));
io.observe(title.value);
run();
});
onBeforeUnmount(() => {
cancelAnimationFrame(raf); io?.disconnect(); mq.removeEventListener('change', run);
removeEventListener('resize', measure);
});
</script>
<template>
<h2 class="ltwv-title" ref="title" aria-label="TITLE"
@pointermove="(mx = $event.clientX) && (boost = 1)" @pointerleave="boost = 0">
<span v-for="(ch, i) in TITLE.split('')" :key="i" class="ltwv-u" aria-hidden="true">{{ ch === ' ' ? '\u00A0' : ch }}</span>
</h2>
<label class="ltwv-amp">
Swell
<input type="range" min="0" max="2" step="0.05" v-model.number="amp" />
</label>
</template>
<style scoped>
.ltwv-title { display: flex; flex-wrap: wrap; margin: 0; font: 900 clamp(2rem, 8vw, 4rem)/1.1 'IBM Plex Sans', sans-serif;
perspective: 500px; cursor: default; }
.ltwv-u { display: inline-block; will-change: transform; }
.ltwv-amp { display: flex; gap: .6rem; align-items: center; margin-block-start: 1rem; }
</style>
<!-- LetterWave.svelte — letters bob like a wave; the pointer's neighbours leap -->
<script>
import { onMount } from 'svelte';
import '@nabuxai/ui-core/css';
const TITLE = 'MAKING WAVES';
let title;
let amp = $state(1);
let units = [], raf = 0, io = null, t0 = 0, mx = 0, boost = 0;
const mq = matchMedia('(prefers-reduced-motion: reduce)');
function measure() {
units = [...title.querySelectorAll('.ltwv-u')].map((u) => ({
el: u, x: u.getBoundingClientRect().x + u.offsetWidth / 2,
}));
}
function frame(now) {
const t = (now - t0) / 1000;
units.forEach((u, i) => {
const near = Math.exp(-((u.x - mx) ** 2) / 9800) * boost;
const y = Math.sin(t * 2.2 + i * 0.55) * 10 * amp * (1 + 2 * near);
const r = Math.sin(t * 2.2 + i * 0.55 + 0.9) * 3 * amp * (1 + near);
u.el.style.transform = `translateY(${y.toFixed(2)}px) rotate(${r.toFixed(2)}deg)`;
});
raf = requestAnimationFrame(frame);
}
function run() { cancelAnimationFrame(raf); if (!mq.matches) raf = requestAnimationFrame(frame); }
onMount(() => {
t0 = performance.now();
measure();
addEventListener('resize', measure);
mq.addEventListener('change', run);
io = new IntersectionObserver(([e]) => (e.isIntersecting ? run() : cancelAnimationFrame(raf)));
io.observe(title);
run();
return () => {
cancelAnimationFrame(raf); io?.disconnect(); mq.removeEventListener('change', run);
removeEventListener('resize', measure);
};
});
</script>
<h2 class="ltwv-title" bind:this={title} aria-label={TITLE}
onpointermove={(e) => { mx = e.clientX; boost = 1; }} onpointerleave={() => (boost = 0)}>
{#each TITLE.split('') as ch, i}
<span class="ltwv-u" aria-hidden="true">{ch === ' ' ? '\u00A0' : ch}</span>
{/each}
</h2>
<label class="ltwv-amp">
Swell
<input type="range" min="0" max="2" step="0.05" bind:value={amp} oninput={(e) => (amp = Number(e.target.value))} />
</label>
<style>
.ltwv-title { display: flex; flex-wrap: wrap; margin: 0; font: 900 clamp(2rem, 8vw, 4rem)/1.1 'IBM Plex Sans', sans-serif;
perspective: 500px; cursor: default; }
.ltwv-u { display: inline-block; will-change: transform; }
.ltwv-amp { display: flex; gap: .6rem; align-items: center; margin-block-start: 1rem; }
</style>