滚动纵深隧道
Scroll Perspective Tunnel
成组边框从纵深处接近镜头,滚动进度直接控制空间推进。
适用场景
用于作品集或线上展览的短时沉浸式开场。 适合很短的开场区。框线之间留足间隔来表现远近,标题和入口放在运动框架之外。
应用示例
线上车站艺术展的入口画面里,观众下滚时,矩形框从远处一层层靠近。穿过最后一层后,展览标题出现在静止的画面上。
AI 提示词
给【目标位置】添加滚动纵深隧道。在同一透视容器下为重复框架分配不同的 Z 轴位置,限制位移避免越过镜头平面。减少动态效果时显示平面嵌套框架。保留键盘操作,并提供减少动态效果时的状态。
示例代码
保存为 HTML 文件后,用浏览器打开即可运行。代码与页面里的演示一致。
查看 HTML
<!doctype html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>滚动纵深隧道</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;
}
.scroll-port {
--frame: clamp(112px, 75vh, 242px);
--p: 0;
width: min(100%, 290px); height: var(--frame);
overflow-y:auto; overflow-x:hidden; scroll-behavior:auto;
overscroll-behavior:contain; scrollbar-width:thin;
scrollbar-color:#a79bd5 #20223d; border-radius:12px;
border:1px solid #a79bd567; background:#20233c; color:#f5f2ff;
}
.scroll-port:focus-visible { outline-offset: 3px; }
.scroll-track { position:relative; min-height:calc(var(--frame) + 235px); }
.scroll-pin { position:sticky; top:0; height:var(--frame); overflow:hidden; }
.scroll-pin .tag { position:absolute; z-index:4; left:8px; bottom:9px; font-size:10px; color:#ecfcff; padding:4px 6px; background:#17152ce8; border-radius:4px; }
.scroll-panel { min-height:62px; padding:9px; border:1px solid #adb2e345; border-radius:8px; background:linear-gradient(120deg,#314861,#3e346a); }
.depth-portal { position:absolute; inset:0; display:grid; place-items:center; perspective:220px; background:radial-gradient(ellipse,#3e4271,#141932 77%); }
.depth-portal i { position:absolute; width:105px; height:76px; border-radius:6px; border:2px solid hsl(var(--h) 90% 76%); box-shadow:0 0 11px hsl(var(--h) 80% 70% / .45),inset 0 0 15px hsl(var(--h) 90% 65% / .27);
transform:translateZ(calc(-560px + var(--i) * 77px + var(--p) * 216px)) rotate(calc(var(--i) * 5deg + var(--p) * 15deg)); }
@media (prefers-reduced-motion:reduce) { .depth-portal i { transform:scale(calc(.3 + var(--i) * .14)) rotate(calc(var(--i) * 5deg)); } }
@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 scroll-port" role="region" tabindex="0" aria-label="滚动穿过纵深框架"><div class="scroll-track"><div class="scroll-pin"><div class="depth-portal" aria-hidden="true"><i style="--i:0;--h:176"></i><i style="--i:1;--h:191"></i><i style="--i:2;--h:206"></i><i style="--i:3;--h:221"></i><i style="--i:4;--h:236"></i><i style="--i:5;--h:251"></i><i style="--i:6;--h:266"></i></div><span class="tag" aria-hidden="true">纵深框架</span></div></div></div>
</main>
<script>
const port = document.querySelector('.scroll-port');
const reduced = matchMedia('(prefers-reduced-motion: reduce)');
const listeners = [];
let scheduled = 0;
function sample() {
const max = Math.max(1,port.scrollHeight - port.clientHeight);
return Math.max(0,Math.min(1,port.scrollTop / max));
}
function update() {
scheduled = 0;
const progress = sample();
port.style.setProperty('--p', progress.toFixed(4));
for (const callback of listeners) callback(progress);
}
function schedule() { if (!scheduled) scheduled = requestAnimationFrame(update); }
function onScroll(callback) { listeners.push(callback); callback(sample()); }
port.addEventListener('scroll', schedule, {passive:true});
new ResizeObserver(schedule).observe(port);
reduced.addEventListener('change', schedule);
update();
</script>
</body>
</html>UI Skills 原创示例