Kinetic Pagination
Page navigation with previous and next buttons, ellipsis for long ranges and a highlight that slides to the current page.
- <kt-kinetic-pagination>
- Navigation
- No framework
The code
Copy the Kinetic Pagination
Fastest: press Copy on the card above for one complete file. To build it into your own
project, use the files below: the markup, the styles, this component’s script and the shared
effects script (effects.js) that every component uses.
<kt-kinetic-pagination total="24" page="8" label="Search results pages"></kt-kinetic-pagination>
<kt-kinetic-pagination total="5" page="2" label="Changelog pages"></kt-kinetic-pagination>
kt-kinetic-pagination {
display: inline-block;
max-width: 100%;
}
.kt-pagination {
--_color: var(--kt-accent);
--_ink: var(--kt-accent-ink);
display: block;
max-width: 100%;
}
.kt-pagination-list {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 2px;
margin: 0;
padding: 0;
list-style: none;
}
.kt-pagination-track {
position: relative;
display: inline-block;
box-sizing: border-box;
max-width: 100%;
padding: 4px;
border-radius: var(--kt-surface-radius);
border-style: solid;
border-width: var(--kt-card-border-w);
border-color: var(--kt-comp-border, var(--kt-surface-border));
background: var(--kt-surface-bg);
box-shadow: var(--kt-comp-shadow);
isolation: isolate;
transition: border-color 160ms ease, box-shadow 180ms ease, border-width 150ms ease;
}
.kt-pagination-item {
display: flex;
margin: 0;
padding: 0;
}
.kt-pagination-glider {
position: absolute;
top: 0;
left: 0;
z-index: 0;
pointer-events: none;
opacity: 0;
transition: transform 280ms var(--ease-overshoot), width 280ms var(--ease-overshoot), height 280ms ease;
}
[data-vfx="enterprise"] .kt-pagination-glider {
transition: transform 160ms ease, width 160ms ease, height 160ms ease;
}
[data-vfx="elastic"] .kt-pagination-glider {
transition: transform 440ms cubic-bezier(0.34, 1.56, 0.64, 1), width 440ms cubic-bezier(0.34, 1.56, 0.64, 1);
}
[data-vfx="glitch"] .kt-pagination-glider {
transition: transform 170ms steps(4, end), width 170ms steps(4, end);
}
[data-vfx="neon"] .kt-pagination-glider,
[data-vfx="ink"] .kt-pagination-glider {
transition: transform 250ms var(--ease-snap), width 250ms var(--ease-snap);
}
.kt-pagination-glider-core {
display: block;
width: 100%;
height: 100%;
border-radius: var(--kt-radius-btn);
background: var(--_color);
}
[data-vfx="neon"] .kt-pagination-glider-core {
box-shadow: 0 0 14px -2px color-mix(in srgb, var(--_color) 75%, transparent);
}
.kt-pagination-glider.is-gliding .kt-pagination-glider-core {
animation: kt-pagination-smear 280ms var(--ease-overshoot);
}
[data-vfx="enterprise"] .kt-pagination-glider.is-gliding .kt-pagination-glider-core {
animation: none;
}
[data-vfx="elastic"] .kt-pagination-glider.is-gliding .kt-pagination-glider-core {
animation: kt-pagination-jelly 440ms cubic-bezier(0.34, 1.56, 0.64, 1);
}
[data-vfx="glitch"] .kt-pagination-glider.is-gliding .kt-pagination-glider-core {
animation: kt-pagination-glitch 180ms steps(4, end);
}
.kt-pagination-btn {
position: relative;
z-index: 1;
display: inline-flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
min-width: 32px;
height: 32px;
padding: 0 8px;
border: 0;
border-radius: var(--kt-radius-btn);
background: transparent;
color: var(--kt-surface-muted);
font-family: var(--font-sans);
font-size: 13px;
font-weight: 700;
font-variant-numeric: tabular-nums;
line-height: 1;
cursor: pointer;
user-select: none;
transition: color 160ms ease, background-color 140ms ease;
}
.kt-pagination-btn:hover {
color: var(--kt-surface-ink);
background: color-mix(in srgb, var(--kt-surface-ink) 8%, transparent);
}
.kt-pagination-btn[aria-current="page"] {
color: var(--_ink);
background: transparent;
cursor: default;
}
.kt-pagination-btn[aria-disabled="true"] {
opacity: 0.35;
cursor: not-allowed;
background: transparent;
color: var(--kt-surface-muted);
}
.kt-pagination-btn:focus-visible {
outline: 2px solid var(--kt-surface-ink);
outline-offset: 1px;
}
.kt-pagination-gap {
display: inline-flex;
align-items: center;
justify-content: center;
min-width: 24px;
height: 32px;
color: var(--kt-surface-muted);
font-family: var(--font-mono);
font-size: 13px;
user-select: none;
}
.kt-pagination-status {
position: absolute;
width: 1px;
height: 1px;
margin: -1px;
padding: 0;
overflow: hidden;
clip: rect(0 0 0 0);
white-space: nowrap;
border: 0;
}
@keyframes kt-pagination-smear {
0% { transform: scale(1, 1); }
35% { transform: scale(1.14, 0.86); }
72% { transform: scale(0.95, 1.07); }
100% { transform: scale(1, 1); }
}
@keyframes kt-pagination-jelly {
0% { transform: scale(1, 1); }
30% { transform: scale(1.18, 0.8); }
60% { transform: scale(0.93, 1.09); }
100% { transform: scale(1, 1); }
}
@keyframes kt-pagination-glitch {
0% { transform: skewX(-10deg) translateX(-2px); }
50% { transform: skewX(8deg) translateX(2px); }
100% { transform: skewX(0) translateX(0); }
}
class KtKineticPagination extends HTMLElement {
static get observedAttributes() {
return ["total", "page", "siblings", "label", "sfx"];
}
constructor() {
super();
this._rendered = false;
this._ro = null;
this._glideTimer = null;
}
connectedCallback() {
if (!this._rendered) {
this.render();
this._rendered = true;
}
this.syncAttributes();
requestAnimationFrame(() => this.updateGlider(false));
}
disconnectedCallback() {
this._ro?.disconnect();
clearTimeout(this._glideTimer);
}
attributeChangedCallback() {
if (!this._rendered) return;
const animate = this._animateNext;
this._animateNext = false;
this.syncAttributes();
if (animate) this.updateGlider(true);
else requestAnimationFrame(() => this.updateGlider(false));
}
get total() {
const n = Math.trunc(Number(this.getAttribute("total") || 10));
return Number.isFinite(n) ? Math.max(1, n) : 10;
}
get page() {
const n = Math.trunc(Number(this.getAttribute("page") || 1));
return Number.isFinite(n) ? Math.min(Math.max(1, n), this.total) : 1;
}
set page(v) { this.setAttribute("page", String(v)); }
get siblings() {
const n = Math.trunc(Number(this.getAttribute("siblings") ?? 1));
return Number.isFinite(n) ? Math.min(Math.max(0, n), 5) : 1;
}
get label() { return this.getAttribute("label") || "Pagination"; }
get sfx() { return this.getAttribute("sfx") ?? "ピタッ!"; }
/** Page numbers and "gap" markers; the length stays the same while you move around. */
pageItems() {
const total = this.total;
const page = this.page;
const sib = this.siblings;
const range = (a, b) => Array.from({ length: Math.max(0, b - a + 1) }, (_, i) => a + i);
if (total <= sib * 2 + 5) return range(1, total);
const start = [1];
const end = [total];
const sibStart = Math.max(Math.min(page - sib, total - 1 - sib * 2 - 1), 3);
const sibEnd = Math.min(Math.max(page + sib, 2 + sib * 2 + 1), total - 2);
return [
...start,
sibStart > 3 ? "gap" : 2,
...range(sibStart, sibEnd),
sibEnd < total - 2 ? "gap" : total - 1,
...end
];
}
render() {
this._ro?.disconnect();
this.innerHTML = "";
const nav = document.createElement("nav");
nav.className = "kt-pagination";
nav.innerHTML = `
<div class="kt-pagination-track">
<span class="kt-pagination-glider" aria-hidden="true"><span class="kt-pagination-glider-core"></span></span>
<ul class="kt-pagination-list"></ul>
</div>
<span class="kt-pagination-status" role="status" aria-live="polite"></span>
`;
this._nav = nav;
this._track = nav.querySelector(".kt-pagination-track");
this._list = nav.querySelector(".kt-pagination-list");
this._glider = nav.querySelector(".kt-pagination-glider");
this._status = nav.querySelector(".kt-pagination-status");
this._list.addEventListener("click", (e) => {
const btn = e.target.closest("button[data-go]");
if (!btn || btn.getAttribute("aria-disabled") === "true") return;
this.goTo(this.resolveTarget(btn.getAttribute("data-go")), true);
});
this._list.addEventListener("keydown", (e) => this.onKeydown(e));
this.appendChild(nav);
if (typeof ResizeObserver !== "undefined") {
this._ro = new ResizeObserver(() => this.updateGlider(false));
this._ro.observe(this._track);
}
}
resolveTarget(go) {
if (go === "prev") return this.page - 1;
if (go === "next") return this.page + 1;
return Number(go);
}
makeItem(inner) {
const li = document.createElement("li");
li.className = "kt-pagination-item";
li.appendChild(inner);
return li;
}
makeButton(go, text, ariaLabel, cls) {
const btn = document.createElement("button");
btn.type = "button";
btn.className = "kt-pagination-btn " + cls;
btn.setAttribute("data-go", go);
btn.setAttribute("aria-label", ariaLabel);
if (text instanceof Node) btn.appendChild(text);
else btn.textContent = text;
return btn;
}
arrow(dir) {
const ns = "http://www.w3.org/2000/svg";
const svg = document.createElementNS(ns, "svg");
svg.setAttribute("viewBox", "0 0 16 16");
svg.setAttribute("width", "14");
svg.setAttribute("height", "14");
svg.setAttribute("aria-hidden", "true");
const path = document.createElementNS(ns, "path");
path.setAttribute("d", dir === "prev" ? "M10 3.5L5.5 8l4.5 4.5" : "M6 3.5L10.5 8 6 12.5");
path.setAttribute("fill", "none");
path.setAttribute("stroke", "currentColor");
path.setAttribute("stroke-width", "2");
path.setAttribute("stroke-linecap", "round");
path.setAttribute("stroke-linejoin", "round");
svg.appendChild(path);
return svg;
}
syncAttributes() {
if (!this._nav) return;
const hadFocus = this._list.contains(document.activeElement);
const focusedKey = hadFocus ? document.activeElement.getAttribute("data-go") : null;
const page = this.page;
const total = this.total;
this._nav.setAttribute("aria-label", this.label);
[...this._list.querySelectorAll(".kt-pagination-item")].forEach((li) => li.remove());
const prev = this.makeButton("prev", this.arrow("prev"), "Previous page", "kt-pagination-nav");
prev.setAttribute("aria-disabled", String(page <= 1));
this._list.appendChild(this.makeItem(prev));
this._pageButtons = {};
this.pageItems().forEach((it) => {
if (it === "gap") {
const gap = document.createElement("span");
gap.className = "kt-pagination-gap";
gap.setAttribute("aria-hidden", "true");
gap.textContent = "…";
this._list.appendChild(this.makeItem(gap));
return;
}
const btn = this.makeButton(String(it), String(it), `Page ${it}`, "kt-pagination-page");
if (it === page) btn.setAttribute("aria-current", "page");
this._pageButtons[it] = btn;
this._list.appendChild(this.makeItem(btn));
});
const next = this.makeButton("next", this.arrow("next"), "Next page", "kt-pagination-nav");
next.setAttribute("aria-disabled", String(page >= total));
this._list.appendChild(this.makeItem(next));
this._status.textContent = `Page ${page} of ${total}`;
this._current = this._pageButtons[page] || null;
if (hadFocus) {
const same = this._list.querySelector(`button[data-go="${focusedKey}"]`);
const keep = same && same.getAttribute("aria-disabled") !== "true" ? same : this._current;
keep?.focus({ preventScroll: true });
}
}
buttons() {
return [...this._list.querySelectorAll("button.kt-pagination-btn")].filter(
(b) => b.getAttribute("aria-disabled") !== "true"
);
}
onKeydown(e) {
const list = this.buttons();
const idx = list.indexOf(document.activeElement);
if (idx < 0) return;
let next = null;
if (e.key === "ArrowRight") next = Math.min(list.length - 1, idx + 1);
else if (e.key === "ArrowLeft") next = Math.max(0, idx - 1);
else if (e.key === "Home") next = 0;
else if (e.key === "End") next = list.length - 1;
if (next !== null) {
e.preventDefault();
list[next].focus();
}
}
updateGlider(animate) {
if (!this._glider) return;
const btn = this._current;
if (!btn || !btn.offsetWidth) {
this._glider.style.opacity = "0";
return;
}
this._glider.style.opacity = "1";
const apply = () => {
const b = btn.getBoundingClientRect();
const t = this._track.getBoundingClientRect();
const x = b.left - t.left - this._track.clientLeft;
const y = b.top - t.top - this._track.clientTop;
this._glider.style.width = `${btn.offsetWidth}px`;
this._glider.style.height = `${btn.offsetHeight}px`;
this._glider.style.transform = `translate(${Math.round(x)}px, ${Math.round(y)}px)`;
};
if (animate) return apply();
const prev = this._glider.style.transition;
this._glider.style.transition = "none";
apply();
void this._glider.offsetWidth;
this._glider.style.transition = prev;
}
goTo(target, fromUser) {
const next = Math.min(Math.max(1, target), this.total);
const prev = this.page;
if (next === prev) return;
this._animateNext = true;
this.page = next;
if (fromUser) {
this.dispatchEvent(new CustomEvent("change", { bubbles: true, detail: { page: next } }));
}
if (SakugaFX.getMode() === "enterprise" || !this._current) return;
this._glider.classList.remove("is-gliding");
void this._glider.offsetWidth;
this._glider.classList.add("is-gliding");
clearTimeout(this._glideTimer);
this._glideTimer = setTimeout(() => this._glider.classList.remove("is-gliding"), 450);
const rect = this._current.getBoundingClientRect();
SakugaFX.emitImpact(rect.left + rect.width / 2, rect.top + rect.height / 2, readAccent(this._nav), {
sfx: this.sfx, scale: 0.7, dirX: next > prev ? 1 : -1, sfxY: rect.top - 2
});
}
}
customElements.define("kt-kinetic-pagination", KtKineticPagination);
function contrastInk(hex) {
const clean = hex.replace("#", "");
if (clean.length !== 6) return "#ffffff";
const r = parseInt(clean.slice(0, 2), 16);
const g = parseInt(clean.slice(2, 4), 16);
const b = parseInt(clean.slice(4, 6), 16);
const lum = (0.299 * r + 0.587 * g + 0.114 * b) / 255;
return lum > 0.6 ? "#09090b" : "#ffffff";
}
function readAccent(el) {
const val = getComputedStyle(el).getPropertyValue("--kt-accent").trim();
return val || "#09090b";
}
class SakugaVFXEngine {
constructor(canvas) {
this.canvas = canvas;
this.ctx = canvas.getContext("2d");
this.items = [];
this.rafId = null;
this.lastTime = 0;
this.textEnabled = false;
this.textOverride = "";
this.vfxTextColor = "auto";
this.resize();
window.addEventListener("resize", () => this.resize());
}
attach(canvas) {
this.canvas = canvas;
this.ctx = canvas.getContext("2d");
this.items = [];
this.resize();
}
resize() {
const dpr = Math.min(window.devicePixelRatio || 1, 2);
this.canvas.width = Math.floor(window.innerWidth * dpr);
this.canvas.height = Math.floor(window.innerHeight * dpr);
this.ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
}
getMode() {
if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) return "enterprise";
return document.documentElement.getAttribute("data-vfx") || "enterprise";
}
wake() {
if (this.rafId !== null) return;
this.lastTime = performance.now();
const tick = (now) => {
const dt = Math.min((now - this.lastTime) / 1000, 0.05);
this.lastTime = now;
this.render(dt);
if (this.items.length > 0) {
this.rafId = requestAnimationFrame(tick);
} else {
this.rafId = null;
this.ctx.clearRect(0, 0, window.innerWidth, window.innerHeight);
}
};
this.rafId = requestAnimationFrame(tick);
}
emitBurst(x, y, color, { count = 14, speed = 240, spread = Math.PI * 2, baseAngle = 0, shards = true } = {}) {
if (this.getMode() === "enterprise") return;
for (let i = 0; i < count; i++) {
const angle = baseAngle + (Math.random() - 0.5) * spread;
const vel = speed * (0.45 + Math.random() * 0.75);
this.items.push({
kind: shards && i % 3 === 0 ? "shard" : "spark",
x, y,
vx: Math.cos(angle) * vel,
vy: Math.sin(angle) * vel - (spread > 4 ? 35 : 0),
gravity: 400,
drag: 0.94,
size: 3 + Math.random() * 4,
rot: Math.random() * Math.PI * 2,
vrot: (Math.random() - 0.5) * 14,
life: 0,
maxLife: 0.32 + Math.random() * 0.22,
color
});
}
this.wake();
}
emitShockwave(x, y, color, maxRadius = 64) {
if (this.getMode() === "enterprise") return;
this.items.push({ kind: "ring", x, y, radius: 8, maxRadius, life: 0, maxLife: 0.32, color });
this.wake();
}
emitSlash(x, y, color, angle = -0.3) {
if (this.getMode() === "enterprise") return;
this.items.push({ kind: "slash", x, y, angle, length: 96, life: 0, maxLife: 0.2, color });
this.wake();
}
emitSmoke(x, y, color, dirX = 0) {
if (this.getMode() === "enterprise") return;
for (let i = 0; i < 4; i++) {
this.items.push({
kind: "smoke",
x: x + (Math.random() - 0.5) * 8,
y: y + (Math.random() - 0.5) * 8,
vx: dirX * (50 + Math.random() * 70) + (Math.random() - 0.5) * 35,
vy: -20 - Math.random() * 50,
size: 5 + Math.random() * 5,
life: 0,
maxLife: 0.34 + Math.random() * 0.16,
color
});
}
this.wake();
}
emitPixels(x, y, color, count = 14) {
if (this.getMode() !== "glitch") return;
for (let i = 0; i < count; i++) {
const angle = Math.floor(Math.random() * 8) * (Math.PI / 4);
const vel = 120 + Math.random() * 200;
this.items.push({
kind: "pixel",
x: x + (Math.random() - 0.5) * 18,
y: y + (Math.random() - 0.5) * 12,
vx: Math.cos(angle) * vel,
vy: Math.sin(angle) * vel,
size: 4 + Math.floor(Math.random() * 5),
life: 0,
maxLife: 0.24 + Math.random() * 0.14,
color
});
}
this.wake();
}
emitScanline(x, y, color, width = 120) {
if (this.getMode() !== "glitch") return;
for (let i = -1; i <= 1; i += 2) {
this.items.push({
kind: "scanline",
x,
y: y + i * (5 + Math.random() * 6),
width,
life: 0,
maxLife: 0.18,
color
});
}
this.wake();
}
emitRays(x, y, color, count = 10, maxRadius = 72) {
if (this.getMode() !== "neon") return;
for (let i = 0; i < count; i++) {
const angle = (Math.PI * 2 * i) / count + (Math.random() - 0.5) * 0.18;
this.items.push({
kind: "ray",
x,
y,
angle,
maxRadius: maxRadius * (0.75 + Math.random() * 0.45),
life: 0,
maxLife: 0.34,
color
});
}
this.wake();
}
emitInkSplatter(x, y, color, count = 14) {
if (this.getMode() !== "ink") return;
for (let i = 0; i < count; i++) {
const angle = Math.random() * Math.PI * 2;
const vel = 110 + Math.random() * 230;
this.items.push({
kind: "inkblot",
x,
y,
vx: Math.cos(angle) * vel,
vy: Math.sin(angle) * vel - 30,
gravity: 480,
drag: 0.91,
size: 2.5 + Math.random() * 5.5,
life: 0,
maxLife: 0.38 + Math.random() * 0.22,
color
});
}
// Brush arc sweep
this.items.push({
kind: "brusharc",
x,
y,
radius: 24 + Math.random() * 14,
startAngle: -Math.PI * 0.75,
endAngle: Math.PI * 0.35,
life: 0,
maxLife: 0.26,
color
});
this.wake();
}
emitMangaSFX(x, y, text, color) {
const mode = this.getMode();
const finalText = this.textOverride || text;
if (mode === "enterprise" || !this.textEnabled || !finalText || finalText === "none") return;
const fillColor = this.vfxTextColor !== "auto" ? this.vfxTextColor : color;
const outline = this.vfxTextColor !== "auto"
? contrastInk(this.vfxTextColor)
: (document.documentElement.getAttribute("data-bw") === "dark" ? "#09090b" : "#ffffff");
this.items.push({
kind: "sfx",
x: x + (Math.random() - 0.5) * 14,
y: y - 16,
vy: -48,
tilt: (Math.random() - 0.5) * 0.26,
text: finalText,
life: 0,
maxLife: 0.6,
color: fillColor,
outline
});
this.wake();
}
emitImpact(x, y, color, { sfx = "", scale = 1, dirX = 0, sfxY = y - 4 } = {}) {
const mode = this.getMode();
if (mode === "enterprise") return;
if (mode === "elastic") {
this.emitShockwave(x, y, color, Math.round(52 * scale));
this.emitSmoke(x, y, color, dirX);
} else if (mode === "glitch") {
this.emitPixels(x, y, color, Math.round(12 * scale));
this.emitScanline(x, y, color, Math.round(96 * scale));
} else if (mode === "neon") {
this.emitShockwave(x, y, color, Math.round(58 * scale));
this.emitRays(x, y, color, Math.round(9 * scale), Math.round(52 * scale));
} else if (mode === "ink") {
this.emitInkSplatter(x, y, color, Math.round(13 * scale));
} else {
this.emitShockwave(x, y, color, Math.round(50 * scale));
this.emitBurst(x, y, color, {
count: Math.round(12 * scale),
speed: Math.round(210 * scale),
spread: dirX ? 1.8 : Math.PI * 2,
baseAngle: dirX < 0 ? Math.PI : 0
});
this.emitSlash(x, y, color, -0.28);
}
this.emitMangaSFX(x, sfxY, sfx, color);
}
render(dt) {
const ctx = this.ctx;
ctx.clearRect(0, 0, window.innerWidth, window.innerHeight);
const next = [];
for (const p of this.items) {
p.life += dt;
if (p.life >= p.maxLife) continue;
const t = p.life / p.maxLife;
const easeOut = 1 - Math.pow(1 - t, 3);
const alpha = Math.max(0, 1 - Math.pow(t, 2));
ctx.save();
ctx.globalAlpha = alpha;
if (p.kind === "spark" || p.kind === "shard") {
p.vx *= Math.pow(p.drag, dt * 60);
p.vy = p.vy * Math.pow(p.drag, dt * 60) + p.gravity * dt;
p.x += p.vx * dt;
p.y += p.vy * dt;
p.rot += p.vrot * dt;
ctx.translate(p.x, p.y);
ctx.rotate(p.rot);
ctx.fillStyle = p.color;
if (p.kind === "shard") {
const s = p.size * (1 - t * 0.4);
ctx.beginPath();
ctx.moveTo(0, -s);
ctx.lineTo(s * 0.72, 0);
ctx.lineTo(0, s);
ctx.lineTo(-s * 0.72, 0);
ctx.closePath();
ctx.fill();
} else {
ctx.beginPath();
ctx.arc(0, 0, p.size * 0.5 * (1 - t * 0.5), 0, Math.PI * 2);
ctx.fill();
}
} else if (p.kind === "ring") {
const r = p.radius + (p.maxRadius - p.radius) * easeOut;
ctx.strokeStyle = p.color;
ctx.lineWidth = Math.max(1, 3 * (1 - t));
ctx.beginPath();
ctx.arc(p.x, p.y, r, 0, Math.PI * 2);
ctx.stroke();
} else if (p.kind === "slash") {
ctx.translate(p.x, p.y);
ctx.rotate(p.angle);
const len = p.length * easeOut;
const th = 4.5 * (1 - t);
ctx.fillStyle = p.color;
ctx.beginPath();
ctx.moveTo(-len, 0);
ctx.quadraticCurveTo(0, -th, len, 0);
ctx.quadraticCurveTo(0, th, -len, 0);
ctx.fill();
} else if (p.kind === "smoke") {
p.x += p.vx * dt;
p.y += p.vy * dt;
const r = p.size * (0.8 + easeOut * 1.25);
ctx.fillStyle = p.color;
ctx.globalAlpha = 0.24 * (1 - t);
ctx.beginPath();
ctx.arc(p.x, p.y, r, 0, Math.PI * 2);
ctx.fill();
} else if (p.kind === "pixel") {
p.x += p.vx * dt;
p.y += p.vy * dt;
ctx.fillStyle = p.color;
const s = p.size * (1 - t * 0.35);
ctx.fillRect(Math.round(p.x - s / 2), Math.round(p.y - s / 2), s, s);
} else if (p.kind === "scanline") {
const w = p.width * (0.4 + easeOut * 0.8);
ctx.fillStyle = p.color;
ctx.fillRect(p.x - w / 2, p.y, w, 2);
} else if (p.kind === "ray") {
const inner = 12 + easeOut * 16;
const outer = inner + p.maxRadius * (1 - t * 0.35);
ctx.strokeStyle = p.color;
ctx.shadowColor = p.color;
ctx.shadowBlur = 10;
ctx.lineWidth = Math.max(1, 2.8 * (1 - t));
ctx.beginPath();
ctx.moveTo(p.x + Math.cos(p.angle) * inner, p.y + Math.sin(p.angle) * inner);
ctx.lineTo(p.x + Math.cos(p.angle) * outer, p.y + Math.sin(p.angle) * outer);
ctx.stroke();
} else if (p.kind === "inkblot") {
p.vx *= Math.pow(p.drag, dt * 60);
p.vy = p.vy * Math.pow(p.drag, dt * 60) + p.gravity * dt;
p.x += p.vx * dt;
p.y += p.vy * dt;
ctx.fillStyle = p.color;
ctx.beginPath();
ctx.arc(p.x, p.y, p.size * (1 - t * 0.45), 0, Math.PI * 2);
ctx.fill();
} else if (p.kind === "brusharc") {
const sweep = p.startAngle + (p.endAngle - p.startAngle) * easeOut;
ctx.strokeStyle = p.color;
ctx.lineCap = "round";
ctx.lineWidth = Math.max(1.5, 6 * (1 - t));
ctx.beginPath();
ctx.arc(p.x, p.y, p.radius * (0.85 + easeOut * 0.4), p.startAngle, sweep);
ctx.stroke();
} else if (p.kind === "sfx") {
p.y += p.vy * dt * (1 - t * 0.6);
const s = t < 0.18 ? 0.55 + (t / 0.18) * 0.65 : 1.2 - (t - 0.18) * 0.25;
ctx.translate(p.x, p.y);
ctx.rotate(p.tilt);
ctx.scale(s, s);
ctx.font = '900 19px "Hiragino Kaku Gothic ProN", "Yu Gothic", system-ui, sans-serif';
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.lineJoin = "round";
ctx.lineWidth = 4.5;
ctx.strokeStyle = p.outline;
ctx.strokeText(p.text, 0, 0);
ctx.fillStyle = p.color;
ctx.fillText(p.text, 0, 0);
}
ctx.restore();
next.push(p);
}
this.items = next;
}
}
const SakugaFX = new SakugaVFXEngine(document.getElementById("sakuga-vfx-canvas"));
window.SakugaFX = SakugaFX;
window.readAccent = readAccent;
window.contrastInk = contrastInk;
Attributes
| Name | What it does | Default |
|---|---|---|
total | Number of pages. | 10 |
page | Current page, starting at 1. | 1 |
siblings | How many page numbers to show on each side of the current page. | 1 |
label | Accessible name of the navigation landmark. | Pagination |
sfx | Sound-effect text on page change. | ピタッ! |
Keyboard and screen readers
- A nav landmark with an aria-label; the current page has aria-current="page".
- Every page button is labeled "Page N"; previous and next are labeled and set aria-disabled at the ends.
- Left and Right Arrow, Home and End move focus between the buttons; Enter or Space opens the focused page.
- A polite live region announces "Page N of M" after a change.
- Fires a change event with the new page number.
Styling variables
Every look is a CSS variable: --kt-accent, --kt-accent-ink, --kt-radius-btn, --kt-surface-radius, --kt-surface-bg, --kt-border-w, --kt-comp-shadow and --font-sans. The
copied file sets them all from your choices.
FAQ
Kinetic Pagination: questions answered
How do I use the Kinetic Pagination?
Press Copy on the card to get a complete HTML file, or copy the HTML, CSS and JavaScript tabs into your own page. In your markup the element is written as <kt-kinetic-pagination>.
Which attributes does <kt-kinetic-pagination> accept?
total, page, siblings, label, sfx. Each one is described in the attributes table on this page.
Is the Kinetic Pagination accessible?
A nav landmark with an aria-label; the current page has aria-current="page". Every page button is labeled "Page N"; previous and next are labeled and set aria-disabled at the ends. Left and Right Arrow, Home and End move focus between the buttons; Enter or Space opens the focused page. A polite live region announces "Page N of M" after a change. Fires a change event with the new page number.
Can I change the Kinetic Pagination colors, corners and font?
Yes. Use the options on this page: accent color, border radius, background, border, shadow and Google font. The copied code already contains your choices, and every one of them is a CSS variable you can edit later.