JavaScript: Copy Text to Clipboard Button
Add a copy-to-clipboard button with plain JavaScript — one click, a "Copied" confirmation, no library needed.
A 3D clothing rack for shop pages: garments turn and grow on hover, open in a detail view, recolour with a jagged wipe from hanging colour tags, and flip to show the back print. Pure HTML, CSS and JS.
373 lines · Updated Nov 26, 2026
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Clothing Rack Product Showcase</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Anton&family=Space+Mono:wght@400;700&family=Inter:wght@500;700;900&display=swap" rel="stylesheet">
<style>
:root {
--bg: #ebeae6; --ink: #111; --accent: #ff4d1a; --muted: #8a8984;
--w: 170px; --railY: 120px;
/* outline of the t-shirt photo (traced), used as a mask so the colour stays inside the shirt */
--sil: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100' preserveAspectRatio='none'%3E%3Cpath d='M64 0L77.1 6.6L84.6 9.4L89.1 12.7L90.9 15.1L90.9 17L99.4 40.6L94.3 43.4L82.9 47.2L80 47.2L78.9 46.2L78.3 43.9L77.7 43.4L77.1 43.9L76 66.5L77.1 70.8L77.1 76.9L78.9 79.2L80.6 90.6L82.9 95.8L75.4 97.2L66.9 97.6L57.7 99.1L36.6 99.5L20 99.5L17.1 96.7L17.7 96.2L17.7 81.6L18.3 81.1L18.3 78.3L21.7 71.7L21.1 70.8L21.7 65.1L22.9 62.3L22.9 59L24 56.6L24 51.9L23.4 51.4L22.9 45.8L22.3 45.3L20.6 47.6L18.9 48.1L10.9 46.2L0 42.5L2.3 38.2L3.4 33L9.7 15.6L14.9 10.8L24 5.7L25.1 5.7L36 0.9L38.9 0.9L42.9 1.9L43.4 1.4L44 1.9L56 1.9L56.6 1.4L62.3 0.9Z'/%3E%3C/svg%3E");
/* jagged edge used by the colour-change wipe */
--wipe: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 300' preserveAspectRatio='none'%3E%3Cpath d='M0 300V150h6v-7h5v11h7v-5h6v9h8v-12h5v6h9v-8h6v10h7v-6h8v7h6v-9h7v5h9v-3h11V300Z'/%3E%3C/svg%3E");
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body { font-family: Inter, system-ui, sans-serif; color: var(--ink); overflow: hidden; -webkit-font-smoothing: antialiased;
background: radial-gradient(ellipse at 50% 30%, #f9f9f7 0%, var(--bg) 55%, #d7d6d1 100%); }
button { font: inherit; color: inherit; }
header { position: fixed; inset: 0 0 auto 0; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
padding: 14px 24px; font: 700 10px/1 "Space Mono", monospace; letter-spacing: .14em; text-transform: uppercase; z-index: 40; }
header .r { justify-self: end; }
.logo { display: flex; align-items: center; gap: 7px; font: 400 21px/1 Anton, Impact, sans-serif; letter-spacing: .06em; }
.logo svg { width: 16px; height: 16px; }
.close { display: none; background: none; border: 0; cursor: pointer; letter-spacing: .14em; text-transform: uppercase; }
body.focus .close { display: inline; } body.focus .contact { display: none; }
/* rail with wall brackets */
.rail { position: absolute; top: var(--railY); left: 5vw; right: 5vw; height: 6px; border-radius: 6px; z-index: 1;
background: linear-gradient(#777, #2b2b2b 55%, #121212); box-shadow: 0 10px 18px rgba(0,0,0,.16); }
.rail::before, .rail::after { content: ""; position: absolute; bottom: 0; width: 7px; height: 30px; border-radius: 2px;
background: linear-gradient(90deg, #1c1c1c, #4a4a4a, #1c1c1c); }
.rail::before { left: 10px; } .rail::after { right: 10px; }
/* one garment */
.item { position: absolute; left: 0; top: calc(var(--railY) - 5px); width: var(--w); perspective: 1100px; transform-origin: 50% 0;
cursor: pointer; font-size: calc(var(--w) * .07); outline: none;
transition: transform .95s cubic-bezier(.22, .8, .2, 1), filter .7s, opacity .7s; }
.spin { transform-style: preserve-3d; transform: rotateY(55deg); transition: transform .85s cubic-bezier(.22, .8, .2, 1); }
.sway { position: relative; transform-style: preserve-3d; }
.item.active .sway { animation: sway 6s ease-in-out infinite alternate; }
@keyframes sway { from { transform: rotateY(-11deg); } to { transform: rotateY(11deg); } }
.hanger { position: relative; display: block; width: 100%; height: auto; margin-bottom: -15%; }
.card { position: relative; aspect-ratio: 700 / 845; transform-style: preserve-3d; transition: transform 1s cubic-bezier(.6, 0, .2, 1); }
.item.show-back .card { transform: rotateY(180deg); }
.face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; container-type: inline-size;
filter: drop-shadow(0 20px 16px rgba(0,0,0,.2)); }
.face.back { transform: rotateY(180deg); }
.item.tank .face { clip-path: polygon(29% 1%, 40% 1%, 44% 9%, 50% 12%, 56% 9%, 60% 1%, 71% 1%, 72% 14%, 74% 26%, 78% 36%, 79.5% 46%, 80% 100%, 17% 100%, 20.5% 46%, 22% 36%, 26% 26%, 28% 14%); }
/* the real photo, recoloured: colour + print sit under the photo, which is multiplied on top for real folds */
.shirt { position: absolute; inset: 0; isolation: isolate;
-webkit-mask: var(--sil) center / 100% 100% no-repeat; mask: var(--sil) center / 100% 100% no-repeat; }
.back .shirt { transform: scaleX(-1); }
.coats, .coat, .tint, .photo, .hi, .trim { position: absolute; inset: 0; width: 100%; height: 100%; }
.photo { background: var(--img) center / 100% 100% no-repeat; mix-blend-mode: multiply; }
.hi { background: var(--img) center / 100% 100% no-repeat; mix-blend-mode: screen; opacity: var(--hi, 0);
filter: grayscale(1) brightness(.34) contrast(1.7); }
.coat.wipe { -webkit-mask: var(--wipe) 0 0 / 100% 300% no-repeat; mask: var(--wipe) 0 0 / 100% 300% no-repeat;
animation: wipe 1.5s cubic-bezier(.55, 0, .3, 1) forwards; }
@keyframes wipe { to { -webkit-mask-position: 0 100%; mask-position: 0 100%; } }
/* prints */
.print { position: absolute; left: 0; right: 0; text-align: center; text-transform: uppercase; }
.back .print { transform: scaleX(-1); }
.print b { display: block; font-family: Anton, Impact, sans-serif; font-weight: 400; }
.print small { display: block; font: 700 3.6cqw/1.2 "Space Mono", monospace; letter-spacing: .14em; }
.print.stack { top: 26%; font: 400 12.5cqw/.9 Anton, Impact, sans-serif; }
.print.chest { top: 23%; left: 56%; right: auto; text-align: left; font: 700 3.6cqw/1.2 "Space Mono", monospace; letter-spacing: .12em; }
.print.brand { top: 27%; } .print.brand b { font-size: 14cqw; line-height: 1; } .print.brand small { margin-top: 2cqw; }
.print.number { top: 21%; } .print.number small { margin-bottom: 2cqw; } .print.number b { font-size: 31cqw; line-height: .9; }
.print.jersey { top: 20%; } .print.jersey small { position: absolute; top: 0; left: 55%; font-size: 3.2cqw; }
.print.jersey i { position: absolute; top: -1cqw; left: 33%; width: 5cqw; height: 6.5cqw; background: currentColor;
clip-path: polygon(0 0, 100% 0, 100% 62%, 50% 100%, 0 62%); }
.print.jersey b { margin-top: 11cqw; font-size: 30cqw; line-height: .9; }
/* colour tags hanging from the hanger */
.tags { position: absolute; top: 2%; left: 59%; display: flex; align-items: flex-start; gap: .35em; transform: translateZ(6px);
opacity: 0; pointer-events: none; transition: opacity .5s; }
.item.active .tags { opacity: 1; pointer-events: auto; transition-delay: .6s; }
.tag { position: relative; margin-top: var(--l); width: 1.25em; height: 4.3em; border-radius: .18em; cursor: pointer; border: 0;
box-shadow: 0 .25em .5em rgba(0,0,0,.2), inset 0 0 0 1px rgba(0,0,0,.12); transform-origin: 50% calc(var(--l) * -1);
animation: tag 3.2s ease-in-out infinite alternate; transition: scale .3s; }
.tag::before { content: ""; position: absolute; left: 50%; bottom: 100%; width: 1px; height: var(--l); background: #8a8a8a; }
.tag::after { content: ""; position: absolute; left: 50%; top: .3em; width: .28em; height: .28em; margin-left: -.14em; border-radius: 50%; background: #e9e9e6; box-shadow: inset 0 1px 1px rgba(0,0,0,.4); }
.tag span { position: absolute; inset: .7em 0 .2em; display: grid; place-items: center; writing-mode: vertical-rl; font: 700 .42em/1 "Space Mono", monospace; letter-spacing: .1em; text-transform: uppercase; white-space: nowrap; }
.tag:nth-child(2) { animation-delay: -1.1s; } .tag:nth-child(3) { animation-delay: -2.2s; }
.tag:hover, .tag.on { scale: 1.12; }
.tag:hover { animation-play-state: paused; }
.tag.on { box-shadow: 0 .25em .5em rgba(0,0,0,.25), 0 0 0 .12em #111; }
@keyframes tag { from { rotate: -5deg; } to { rotate: 5deg; } }
.item.hov .tags { opacity: 1; pointer-events: auto; transition-delay: .35s; }
/* hover label under the rack */
.peek { position: absolute; left: 50%; transform: translate(-50%, 8px); text-align: center; opacity: 0; pointer-events: none;
transition: opacity .35s, transform .35s; z-index: 20; font: 400 11px/1.5 "Space Mono", monospace; }
body.hovering .peek { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
body.focus .peek { opacity: 0; pointer-events: none; }
.peek .sub { color: var(--muted); font-size: 10px; letter-spacing: .1em; }
.peek button { margin-top: 10px; border: 1px solid var(--ink); background: rgba(255,255,255,.4); border-radius: 99px; padding: 7px 14px;
font: 700 9px/1 "Space Mono", monospace; letter-spacing: .14em; text-transform: uppercase; cursor: pointer; }
.peek button:hover { background: var(--ink); color: #fff; }
/* detail panel when a piece is selected */
.info { position: absolute; left: 50%; transform: translate(-50%, 14px); text-align: center; opacity: 0; pointer-events: none;
transition: opacity .5s, transform .5s; z-index: 20; }
body.focus .info { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; transition-delay: .45s; }
.info h2 { font: 900 clamp(20px, 2.5vw, 30px)/1 Inter, sans-serif; letter-spacing: -.01em; text-transform: uppercase; }
.info p { font: 400 10px/1.4 "Space Mono", monospace; color: var(--muted); letter-spacing: .06em; margin: 7px 0 11px; white-space: nowrap; }
.pill { display: inline-flex; border: 1px solid var(--ink); border-radius: 99px; padding: 2px; }
.pill button { border: 0; background: none; padding: 6px 13px; border-radius: 99px; font: 700 9px/1 "Space Mono", monospace; letter-spacing: .14em; text-transform: uppercase; cursor: pointer; }
.pill button.on { background: var(--ink); color: #fff; }
.avail { display: block; margin: 10px auto 0; background: none; border: 0; border-bottom: 1px solid var(--ink); padding-bottom: 2px;
font: 700 9px/1 "Space Mono", monospace; letter-spacing: .14em; text-transform: uppercase; cursor: pointer; }
.nav { position: fixed; top: 46%; width: 34px; height: 34px; border-radius: 50%; border: 1px solid #bdbcb7; background: rgba(255,255,255,.7);
font-size: 13px; cursor: pointer; opacity: 0; pointer-events: none; transition: .4s; z-index: 30; }
body.focus .nav { opacity: 1; pointer-events: auto; }
.nav:hover { background: var(--ink); color: #fff; }
.nav.prev { left: 22px; } .nav.next { right: 22px; }
.ticker { position: fixed; inset: auto 0 0 0; background: var(--accent); overflow: hidden; white-space: nowrap; padding: 9px 0;
font: 900 italic 11px/1 Inter, sans-serif; letter-spacing: .1em; text-transform: uppercase; z-index: 40; }
.ticker div { display: inline-block; animation: marquee 30s linear infinite; }
.ticker span { margin: 0 14px; }
@keyframes marquee { to { transform: translateX(-50%); } }
@media (prefers-reduced-motion: reduce) { .ticker div, .item.active .sway, .tag { animation: none; } }
</style>
</head>
<body>
<header>
<span>About</span>
<span class="logo"><svg viewBox="0 0 16 16"><path d="M8 1 L15 14 H1 Z" fill="none" stroke="#111" stroke-width="2"/></svg>RACKWEAR</span>
<span class="r"><span class="contact">Contact</span><button class="close" id="close">Close ✕</button></span>
</header>
<div class="rail"></div>
<div id="rack"></div>
<div class="peek" id="peek">
<div id="peekName"></div>
<div class="sub" id="peekSub"></div>
<button id="peekBtn">See availability</button>
</div>
<div class="info" id="info">
<h2 id="pName"></h2>
<p id="pMeta"></p>
<div class="pill"><button class="on" data-side="front">Front</button><button data-side="back">Back</button></div>
<button class="avail" id="avail">See availability →</button>
</div>
<button class="nav prev" id="prev" aria-label="Previous piece">←</button>
<button class="nav next" id="next" aria-label="Next piece">→</button>
<div class="ticker"><div id="ticker"></div></div>
<script>
(function () {
// Swap this for your own transparent product photo (same-folder file works best).
var IMG = 'https://penducoder.com/assets/blog/post_iulg0HWLbt6KGdIkhvCv.png';
document.documentElement.style.setProperty('--img', 'url("' + IMG + '")');
var BLACK = { n: 'Washed Black', c: '#2b2b2d', ink: '#eeede8', d: 1 };
var P = [
{ name: 'Rack Logo Tee', type: 'tee', meta: 'Heavyweight 240gsm · Boxy fit', price: 40,
front: { t: 'brand', a: 'Rackwear', b: 'Est. 2026 · Supply' }, back: { t: 'stack', a: ['Built', 'for the', 'rack'] },
v: [BLACK, { n: 'Bone', c: '#e8e1cf', ink: '#1b1b1b' }, { n: 'Clay', c: '#b9653f', ink: '#f4eee3' }] },
{ name: 'Rack Team Tank', type: 'tank', meta: 'Garment-dyed · Raw edges', price: 45,
front: { t: 'chest', a: ['Rack', 'Team'] }, back: { t: 'number', a: 'Rack Team', b: '01' },
v: [BLACK, { n: 'Sky', c: '#94bde0', ink: '#13223b' }, { n: 'Sage', c: '#a2b08c', ink: '#1c2417' }] },
{ name: 'Stacked Tee', type: 'tee', meta: 'Midweight 200gsm · Regular fit', price: 38,
front: { t: 'stack', a: ['Rack', 'Rack', 'Rack'] }, back: { t: 'chest', a: ['Rackwear', 'SS26'] },
v: [{ n: 'Optic White', c: '#f3f2ee', ink: '#e8431a' }, { n: 'Signal Red', c: '#c7322b', ink: '#f5efe6' }, { n: 'Navy', c: '#1e2945', ink: '#f2b84b', d: 1 }] },
{ name: 'Team Jersey', type: 'jersey', meta: 'Mesh-feel cotton · Contrast trims', price: 75,
front: { t: 'jersey', a: 'Rack', b: '07' }, back: { t: 'number', a: 'Rack Team', b: '07' },
v: [{ n: 'Sky / Navy', c: '#8cc1ec', ink: '#13244a', trim: '#13244a' }, { n: 'Orange / Black', c: '#f2672b', ink: '#111', trim: '#111' }, { n: 'White / Green', c: '#f2f1ec', ink: '#1d6a3a', trim: '#1d6a3a' }] },
{ name: 'Club Tank', type: 'tank', meta: 'Rib knit · Athletic cut', price: 42,
front: { t: 'brand', a: 'Rack', b: 'Athletic Dept.' }, back: { t: 'stack', a: ['Run', 'the', 'rack'] },
v: [{ n: 'Heather Grey', c: '#b9b9b6', ink: '#161616' }, { n: 'Forest', c: '#2f4a35', ink: '#efe8d6', d: 1 }, { n: 'Butter', c: '#f1dd8f', ink: '#2a2a2a' }] },
{ name: 'Archive Tee', type: 'tee', meta: 'Vintage wash · Oversized', price: 48,
front: { t: 'number', a: 'Archive', b: '99' }, back: { t: 'chest', a: ['Rackwear', 'Archive 99'] },
v: [{ n: 'Faded Olive', c: '#7c7d55', ink: '#f0ead8' }, { n: 'Ink Black', c: '#1b1b1c', ink: '#e3402a', d: 1 }, { n: 'Sand', c: '#d9c6a3', ink: '#3a2a1a' }] },
{ name: 'Pocket Tee', type: 'tee', meta: 'Midweight · Relaxed fit', price: 36,
front: { t: 'chest', a: ['Rack', 'Supply Co.'] }, back: { t: 'brand', a: 'Rack', b: 'Since 2026' },
v: [{ n: 'Cream', c: '#efe9dc', ink: '#1b1b1b' }, { n: 'Cobalt', c: '#2f56b8', ink: '#f3f0e8' }, { n: 'Brick', c: '#9c3b2a', ink: '#f3ece0' }] }
];
var HANGER = '<svg class="hanger" viewBox="0 0 200 90" aria-hidden="true"><defs>' +
'<linearGradient id="wd" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stop-color="#a8623b"/><stop offset=".5" stop-color="#7b3f22"/><stop offset="1" stop-color="#4b2211"/></linearGradient>' +
'<linearGradient id="cr" x1="0" y1="0" x2="1" y2="0"><stop offset="0" stop-color="#5f5f5f"/><stop offset=".45" stop-color="#f6f6f6"/><stop offset="1" stop-color="#777"/></linearGradient></defs>' +
'<path d="M100 40V22c0-12 15-15 18-6 2 6-3 10-8 9" fill="none" stroke="url(#cr)" stroke-width="3.2" stroke-linecap="round"/>' +
'<path d="M6 80Q100 30 194 80L192 88Q100 42 8 88Z" fill="url(#wd)"/><rect x="95" y="36" width="10" height="9" rx="2" fill="url(#cr)"/></svg>';
var TRIMS = ['polygon(36% 0,64% 0,63% 5%,50% 8.5%,37% 5%)', 'polygon(0 42.5%,2.8% 37%,22.5% 42.5%,20.6% 47.6%)',
'polygon(99.4% 40.6%,97% 35.3%,77.6% 41.7%,80% 47.2%)', 'polygon(15% 94%,85% 92%,85% 100%,15% 100%)'];
function printHTML(pr, ink) {
var st = ' style="color:' + ink + '"';
if (pr.t === 'stack') return '<div class="print stack"' + st + '>' + pr.a.join('<br>') + '</div>';
if (pr.t === 'chest') return '<div class="print chest"' + st + '>' + pr.a.join('<br>') + '</div>';
if (pr.t === 'brand') return '<div class="print brand"' + st + '><b>' + pr.a + '</b><small>' + pr.b + '</small></div>';
if (pr.t === 'number') return '<div class="print number"' + st + '><small>' + pr.a + '</small><b>' + pr.b + '</b></div>';
return '<div class="print jersey"' + st + '><i></i><small>' + pr.a + '</small><b>' + pr.b + '</b></div>';
}
function makeCoat(p, v, side) {
var c = document.createElement('div');
c.className = 'coat';
c.style.setProperty('--hi', v.d ? .5 : 0);
var h = '<div class="tint" style="background:' + v.c + '"></div>';
if (v.trim) TRIMS.forEach(function (cp) { h += '<div class="trim" style="background:' + v.trim + ';clip-path:' + cp + '"></div>'; });
h += printHTML(p[side], v.ink) + '<div class="photo"></div><div class="hi"></div>';
c.innerHTML = h;
return c;
}
function pad(n) { return (n < 10 ? '0' : '') + n; }
var rack = document.getElementById('rack'), body = document.body;
var peek = document.getElementById('peek'), info = document.getElementById('info');
var $ = function (id) { return document.getElementById(id); };
var items = [], state = { hover: -1, focus: -1 }, W = 170, H = 255, leaveT;
P.forEach(function (p, i) {
var el = document.createElement('div');
el.className = 'item ' + p.type;
el.tabIndex = 0;
el.setAttribute('role', 'button');
el.setAttribute('aria-label', p.name);
var tags = p.v.map(function (v, k) {
var l = [1.3, 2.3, 1.7][k % 3];
return '<button class="tag" data-k="' + k + '" aria-label="Colour: ' + v.n + '" style="--l:' + l + 'em;background:' + v.c +
';color:' + (v.d || /^#[0-6]/.test(v.c) ? '#f3f2ee' : '#151515') + '"><span>' + v.n + '</span></button>';
}).join('');
el.innerHTML = '<div class="spin"><div class="sway">' + HANGER +
'<div class="card"><div class="face front"><div class="shirt"></div></div><div class="face back"><div class="shirt"></div></div></div>' +
'<div class="tags">' + tags + '</div></div></div>';
rack.appendChild(el);
var it = { el: el, spin: el.querySelector('.spin'), faces: el.querySelectorAll('.shirt'), tags: el.querySelectorAll('.tag'), v: -1 };
items.push(it);
el.addEventListener('mouseenter', function () { if (state.focus < 0) { clearTimeout(leaveT); setHover(i); } });
el.addEventListener('mouseleave', function () { if (state.focus < 0) scheduleLeave(); });
el.addEventListener('click', function () { if (state.focus !== i) setFocus(i); });
el.addEventListener('keydown', function (e) { if (e.key === 'Enter' && e.target === el) setFocus(i); });
it.tags.forEach(function (t) {
var k = +t.dataset.k;
t.addEventListener('pointerdown', function (e) { e.stopPropagation(); setVariant(i, k); });
t.addEventListener('click', function (e) { e.stopPropagation(); if (e.detail === 0) setVariant(i, k); });
t.addEventListener('mouseenter', function () { text(i, k); });
t.addEventListener('mouseleave', function () { text(i); });
});
setVariant(i, 0);
});
// colour change: a new coat (colour + print + photo) wipes up over the old one with a jagged edge
function setVariant(i, k) {
var it = items[i], p = P[i], v = p.v[k], first = it.v < 0;
if (it.v === k) return;
it.v = k;
['front', 'back'].forEach(function (side, si) {
var sh = it.faces[si], c = makeCoat(p, v, side);
if (!first) {
c.classList.add('wipe');
c.addEventListener('animationend', function () {
while (sh.firstChild && sh.firstChild !== c) sh.removeChild(sh.firstChild);
c.classList.remove('wipe');
});
}
sh.appendChild(c);
});
it.tags.forEach(function (t, n) { t.classList.toggle('on', n === k); });
text(i);
}
function text(i, k) {
var p = P[i], v = p.v[k == null ? items[i].v : k];
if (state.focus === i) {
$('pName').textContent = p.name;
$('pMeta').textContent = v.n + ' · ' + p.meta + ' · $' + p.price;
}
if (state.hover === i || state.focus < 0) {
$('peekName').textContent = p.name + ' · ' + v.n;
$('peekSub').textContent = pad(i + 1) + ' · ' + pad(P.length) + ' · $' + p.price;
}
}
function setHover(i) {
state.hover = i;
body.classList.toggle('hovering', i >= 0);
items.forEach(function (it, n) { it.el.classList.toggle('hov', n === i); });
if (i >= 0) text(i);
layout();
}
function scheduleLeave() { clearTimeout(leaveT); leaveT = setTimeout(function () { setHover(-1); }, 260); }
peek.addEventListener('mouseenter', function () { clearTimeout(leaveT); });
peek.addEventListener('mouseleave', scheduleLeave);
$('peekBtn').addEventListener('click', function () { if (state.hover >= 0) setFocus(state.hover); });
function setFocus(i) {
state.focus = i;
state.hover = -1;
body.classList.remove('hovering');
body.classList.toggle('focus', i >= 0);
items.forEach(function (it) { it.el.classList.remove('show-back', 'hov'); });
side('front');
if (i >= 0) text(i);
layout();
}
function side(s) {
document.querySelectorAll('.pill button').forEach(function (b) { b.classList.toggle('on', b.dataset.side === s); });
if (state.focus >= 0) items[state.focus].el.classList.toggle('show-back', s === 'back');
}
document.querySelectorAll('.pill button').forEach(function (b) { b.addEventListener('click', function () { side(b.dataset.side); }); });
function step(d) { setFocus((state.focus + d + P.length) % P.length); }
$('prev').addEventListener('click', function () { step(-1); });
$('next').addEventListener('click', function () { step(1); });
$('close').addEventListener('click', function () { setFocus(-1); });
$('avail').addEventListener('click', function () {
var b = this; b.textContent = 'In stock · S · M · L · XL';
setTimeout(function () { b.textContent = 'See availability →'; }, 1800);
});
document.addEventListener('keydown', function (e) {
if (state.focus < 0) return;
if (e.key === 'Escape') setFocus(-1);
if (e.key === 'ArrowRight') step(1);
if (e.key === 'ArrowLeft') step(-1);
});
// every garment is placed by JS so idle / hover / selected states can all animate between each other
function layout() {
var vw = innerWidth, vh = innerHeight, n = items.length, root = document.documentElement.style;
var rail = Math.max(84, Math.min(120, vh * .15));
W = Math.max(92, Math.min(175, vw / (n * .6 + 3.4), (vh - rail - 190) / 1.6));
root.setProperty('--w', W + 'px');
root.setProperty('--railY', rail + 'px');
H = items[0].el.offsetHeight;
var top = rail - 11 * W / 200, cx = vw / 2, S = W * .6, f = state.focus, h = state.hover;
var SF = Math.min(1.45, Math.max(1, (vh - top - 36 - 150) / H));
items.forEach(function (it, i) {
var x, s = 1, deg = 55, z = i + 1, soft = false;
if (f >= 0) {
var gap = W * SF / 2 + W * .5;
if (i === f) { x = cx - W / 2; s = SF; deg = 0; z = 100; }
else if (i < f) { x = cx - gap - W - (f - 1 - i) * S; soft = true; }
else { x = cx + gap + (i - f - 1) * S; soft = true; z = n - i; }
} else {
x = cx + (i - (n - 1) / 2) * S - W / 2;
if (h >= 0) {
if (i === h) { s = 1.08; deg = 0; z = 100; }
else x += (i < h ? -1 : 1) * W * .42;
}
}
it.el.style.top = top + 'px';
it.el.style.transform = 'translate3d(' + x + 'px,0,0) scale(' + s + ')';
it.spin.style.transform = 'rotateY(' + deg + 'deg)';
it.el.style.zIndex = z;
it.el.style.filter = soft ? 'blur(3px)' : 'none';
it.el.style.opacity = soft ? .55 : 1;
it.el.classList.toggle('active', i === f);
});
peek.style.top = (top + H * 1.08 + 12) + 'px';
info.style.top = (top + H * SF + 6) + 'px';
}
addEventListener('resize', layout);
layout();
var msg = ['New drop', 'Rackwear SS26', 'Free shipping over $100', 'Hover a piece', 'Click to try colours'];
var row = msg.map(function (m) { return '<span>' + m + '</span><span>✺</span>'; }).join('');
$('ticker').innerHTML = row + row + row + row;
})();
</script>
</body>
</html>
A product rack that feels like a real shop window. Garments hang on wooden hangers along a metal rail, turned sideways. Hover one and it swings round to face you, its neighbours step aside, and a small label shows the name, colour and price.
Click a piece to open the detail view: the rest of the rack slides away and blurs, the garment sways gently in the centre, and the title, details, a Front / Back switch and a See availability link appear underneath.
Plain HTML, CSS and JavaScript in one file. No libraries.
Save the code as an .html file and open it in a browser. To use your own products:
IMG to a transparent PNG of a plain white or light-grey tee (front view, centred). Put it in the same folder as the page.P array: name, type (tee, tank or jersey), meta text, price, front and back print, and the colour variants (c = shirt colour, ink = print colour, d: 1 for dark colours, trim for jersey trims).--sil outline in the CSS so the colour stays inside the shirt.Works in current Chrome, Edge, Firefox and Safari.
Share this snippet
Add a copy-to-clipboard button with plain JavaScript — one click, a "Copied" confirmation, no library needed.
Add a dark mode toggle that remembers the visitor's choice in localStorage — and respects their system setting first.
Stop firing a search request on every keystroke — debounce the input so it only searches after the user pauses typing.