Two-Axis Scroll Minimap
双轴滚动小地图
The overview rectangle tracks both scroll axes and the visible fraction of the map.
Where to use it
Orient people in a canvas editor, large spreadsheet, or spatial board. Use a miniature view that mirrors the full work area and clearly outlines the current viewport. Offer ordinary scroll and keyboard navigation alongside it.
Practical example
In a floor-plan editor, panning right and down moves the minimap rectangle across a thumbnail of the whole floor. That viewport outline shows whether the user is viewing the lobby or a distant corner.
AI prompt
Add Two-Axis Scroll Minimap to [target]. Read scrollLeft, scrollTop, and viewport fractions on the original scrolling surface. Draw the miniature viewport as percentages on an overlay that does not capture input. 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>Two-Axis Scroll Minimap</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;
}
.map-shell { position:relative; contain:inline-size; width:min(100%,290px); height:clamp(112px,75vh,230px); }
.map-viewport { width:100%; height:100%; overflow:scroll; scrollbar-width:thin; scrollbar-color:#a592e1 #192540; overscroll-behavior:contain; border:1px solid #917bdb9e; border-radius:10px; }
.map-picture { position:relative; width:540px; height:375px; background:radial-gradient(ellipse at 65% 56%,#599486 0 12%, transparent 12.5%),radial-gradient(ellipse at 34% 40%,#356177 0 18%,transparent 18.5%),repeating-linear-gradient(0deg,transparent 0 27px,#9dc4cf34 28px 29px),repeating-linear-gradient(90deg,transparent 0 27px,#a5bdca35 28px 29px),#263653; }
.map-picture span { position:absolute; left:var(--x); top:var(--y); color:#fff; background:#64599d; width:23px; aspect-ratio:1; border:1px solid #c6b8ed; border-radius:50%; display:grid; place-items:center; font-size:11px; }
.map-overview { width:62px; aspect-ratio:1.44; position:absolute; right:13px; bottom:13px; pointer-events:none; border:1px solid #adc7d8; border-radius:5px; background:#344e6c; color:#afebe1; }
.map-overview i { position:absolute; width:var(--vw,35%); height:var(--vh,35%); left:var(--px,0%); top:var(--py,0%); border:1px solid currentColor; background:#9fe7d935; }
</style>
</head>
<body>
<main class="demo">
<div class="lab map-shell"><div class="map-viewport" role="region" tabindex="0" aria-label="Scroll the map in both directions"><div class="map-picture" aria-hidden="true"><span style="--x:9%;--y:14%">A</span><span style="--x:70%;--y:17%">B</span><span style="--x:23%;--y:74%">C</span><span style="--x:76%;--y:68%">D</span></div></div><div class="map-overview" aria-hidden="true"><i></i></div></div>
</main>
<script>
const map = document.querySelector('.map-viewport');
const overview = document.querySelector('.map-overview');
function updateMap() {
const width = map.scrollWidth || 1, height = map.scrollHeight || 1;
overview.style.setProperty('--vw', (map.clientWidth / width * 100) + '%');
overview.style.setProperty('--vh', (map.clientHeight / height * 100) + '%');
overview.style.setProperty('--px', (map.scrollLeft / width * 100) + '%');
overview.style.setProperty('--py', (map.scrollTop / height * 100) + '%');
}
map.addEventListener('scroll',updateMap,{passive:true});
new ResizeObserver(updateMap).observe(map);
updateMap();
</script>
</body>
</html>Original example by UI Skills