Dock Neighbor Magnification
程序坞邻近放大
The nearest icon grows the most, while adjacent icons grow less according to distance.
Where to use it
Make the currently targeted item easier to identify in a short launcher. Use it on a short row and reserve space above the icons so magnification keeps adjacent content in place.
Practical example
A browser editor has a bottom dock with six drawing tools. Moving toward the pen makes its icon largest, with the neighboring fill and selection icons growing a little.
AI prompt
Add Dock Neighbor Magnification to [target]. Measure resting icon centers. Map pointer distance through a falloff curve and scale from the bottom edge without changing clickable target sizes. Apply the same calculation on keyboard focus. Keep the controls keyboard accessible and provide a reduced-motion state.
Example code
Save the standalone HTML as a file and open it in your browser. It uses the same code as the preview.
View HTML
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Dock Neighbor Magnification</title>
<style>
:root {
color-scheme: dark;
--demo-bg: #171629;
--demo-ink: #f8f5ff;
--demo-accent: #b9a6ff;
--demo-muted: #bfbbd3;
font-family: system-ui, sans-serif;
color: var(--demo-ink);
background: var(--demo-bg);
}
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; min-width: 0; }
button, input { font: inherit; }
.demo {
display: grid;
place-items: center;
align-content: center;
min-height: 100vh;
padding: 14px;
overflow: hidden;
background: radial-gradient(ellipse at 50% 24%, #28233f, var(--demo-bg) 78%);
}
.demo-button {
border: 1px solid #ffffff3d;
border-radius: 7px;
background: #ffffff12;
color: var(--demo-ink);
padding: 6px 11px;
font-size: 12px;
cursor: pointer;
}
:focus-visible {
outline: 2px solid var(--demo-accent);
outline-offset: 3px;
}
.dock-scene { width:min(100%,280px); height:clamp(106px,68vh,174px); display:grid; place-items:center; align-items:end; padding:12px 0 20px; border:1px solid #a798d45c; border-radius:13px; background: radial-gradient(ellipse at 42% 20%,#394070,#171b34); }
.dock { width:min(100%,214px); padding:7px; display:flex; justify-content:center; gap:6px; border-radius:15px; background:#c3c9ff34; border:1px solid #eef0ff3d; }
.dock button { width:30px; height:32px; min-width:0; padding:0; border:0; border-radius:8px; background:none; color:#fff; cursor:pointer; }
.dock button span { display:grid; place-items:center; width:100%; height:100%; border:1px solid #d1c7f95c; border-radius:inherit; background:#58478a; transform:translateY(calc(var(--weight,0) * -11px)) scale(calc(1 + var(--weight,0) * .44)); transition:transform 130ms ease-out; pointer-events:none; }
.dock button:nth-child(2n) span { background:#327381; }
.dock button[aria-pressed="true"] span { background:#af75b6; }
@media (prefers-reduced-motion: reduce) {
.lab, .lab *, .lab::before, .lab::after, .lab *::before, .lab *::after {
animation: none !important;
transition: none !important;
scroll-behavior: auto !important;
}
}
</style>
</head>
<body>
<main class="demo">
<div class="lab dock-scene"><div class="dock" aria-label="Magnifying dock">
<button type="button" aria-pressed="false" aria-label="Preview icon 1"><span aria-hidden="true">◆</span></button><button type="button" aria-pressed="false" aria-label="Preview icon 2"><span aria-hidden="true">✦</span></button><button type="button" aria-pressed="false" aria-label="Preview icon 3"><span aria-hidden="true">◉</span></button><button type="button" aria-pressed="false" aria-label="Preview icon 4"><span aria-hidden="true">△</span></button><button type="button" aria-pressed="false" aria-label="Preview icon 5"><span aria-hidden="true">▥</span></button>
</div></div>
</main>
<script>
const dock = document.querySelector('.dock');
const buttons = [...dock.querySelectorAll('button')];
function magnify(x) {
buttons.forEach((button) => {
const width = button.offsetWidth;
const center = button.offsetLeft + width / 2;
const weight = x === null ? 0 : Math.exp(-Math.pow((x - center) / 38, 2));
button.style.setProperty('--weight', weight);
});
}
dock.style.position = 'relative';
function position(button) { return button.offsetLeft + button.offsetWidth / 2; }
dock.addEventListener('pointermove', (event) => {
if (event.pointerType !== 'touch' && !matchMedia('(prefers-reduced-motion: reduce)').matches) magnify(event.clientX - dock.getBoundingClientRect().left);
});
dock.addEventListener('pointerleave', () => magnify(null));
dock.addEventListener('focusout', (event) => { if (!dock.contains(event.relatedTarget)) magnify(null); });
buttons.forEach((button) => {
button.addEventListener('focus', () => magnify(position(button)));
button.addEventListener('click', () => {
const active = button.getAttribute('aria-pressed') !== 'true';
buttons.forEach((item) => item.setAttribute('aria-pressed', String(item === button && active)));
magnify(active ? position(button) : null);
});
});
</script>
</body>
</html>Original example by UI Skills