路径描绘与擦除
Draw and Erase Path
线条逐段显现,再从另一端逐段消失,随后重播。
适用场景
在插图里描绘一段简单的路线、趋势或连线。 适合起点和终点都能单独标注的路线,线条擦除后,读者仍知道要观察哪两处。
应用示例
展馆导览在入口与无障碍电梯之间逐段画出一条弧线。线条从起点侧消失后重新播放,两处地标的名称始终保留。
AI 提示词
给【目标线条】加路径描绘与擦除。对单向路径,让裁切窗口从左至右露出线条,再从起点侧隐藏。遇到折返曲线时可用 stroke-dashoffset。减少动态时呈现整条线。
示例代码
保存为 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;
}
.trace {
width: min(100%, 230px); height: 84px; padding: 13px 14px;
background: repeating-linear-gradient(0deg, transparent 0 17px, #6380ab34 17px 18px), #222d48;
border: 1px solid #63769c; border-radius: 10px;
}
.trace-reveal { height: 100%; animation: trace 4s -1s linear infinite; }
.trace-reveal i {
display: block; height: 100%;
clip-path: polygon(0 82%, 22% 45%, 41% 66%, 61% 19%, 79% 39%, 99% 6%, 100% 12%, 79% 46%, 61% 26%, 41% 73%, 22% 52%, 0 89%);
background: linear-gradient(90deg, #7bdac8, #d3baff);
}
@keyframes trace {
0% { clip-path: inset(0 86% 0 0); }
45%, 57% { clip-path: inset(0); }
98%, 100% { clip-path: inset(0 0 0 100%); }
}
.motion-example { display: grid; justify-items: center; width: 100%; gap: 10px; }
.motion-specimen {
display: grid;
place-items: center;
width: min(100%, 295px);
height: 108px;
position: relative;
isolation: isolate;
}
.motion-example [data-motion] { animation-play-state: paused; }
.motion-example[data-playing] [data-motion] { animation-play-state: running; }
@media (prefers-reduced-motion: reduce) {
.motion-example [data-motion] { animation: none; }
.motion-example [data-loop-toggle] { display: none; }
}
</style>
</head>
<body>
<main class="demo">
<div class="motion-example">
<div class="motion-specimen" aria-hidden="true"><div class="trace"><div class="trace-reveal" data-motion><i></i></div></div></div>
<button class="demo-button" type="button" data-loop-toggle data-testid="effect-demo-loop-toggle">播放演示</button>
</div>
</main>
<script>
const example = document.querySelector('.motion-example');
const toggle = example.querySelector('[data-loop-toggle]');
toggle.addEventListener('click', () => {
const playing = example.toggleAttribute('data-playing');
toggle.textContent = playing ? "暂停演示" : "播放演示";
});
</script>
</body>
</html>UI Skills 原创示例