| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <!DOCTYPE html>
- <html lang="zh-CN">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>SVG Motion Path - Animal.js</title>
- <link rel="stylesheet" href="../demo.css">
- <style>
- .demo-visual {
- padding: 26px 30px;
- background: #151515;
- display: grid;
- grid-template-columns: 1fr 280px;
- gap: 16px;
- }
- .stage {
- background: rgba(0,0,0,0.25);
- border: 1px solid #262626;
- border-radius: 12px;
- padding: 14px;
- overflow: hidden;
- min-height: 220px;
- display: grid;
- place-items: center;
- }
- .panel {
- background: rgba(0,0,0,0.18);
- border: 1px solid #262626;
- border-radius: 12px;
- padding: 14px;
- display: flex;
- flex-direction: column;
- gap: 12px;
- }
- svg { width: 100%; height: 100%; max-height: 260px; }
- .path {
- fill: none;
- stroke: rgba(255,255,255,0.12);
- stroke-width: 2.2;
- stroke-linecap: round;
- stroke-linejoin: round;
- }
- .runner {
- fill: var(--accent-color);
- filter: drop-shadow(0 0 8px rgba(255,159,67,0.25));
- }
- </style>
- </head>
- <body>
- <div class="container">
- <div class="page-top">
- <div class="crumb">ANIMATION › SVG</div>
- <div class="since">SINCE 1.0.0</div>
- </div>
- <h1>沿路径运动(Motion Path)</h1>
- <p class="description">让一个小点沿着 path 跑:像小飞机巡航、像精灵带路、像 UI 的“引导线”。</p>
- <div class="box-container">
- <div class="demo-visual">
- <div class="stage">
- <svg viewBox="0 0 320 180">
- <path id="track" class="path" d="M18,142 C62,14 142,12 176,90 C204,154 262,166 300,42" />
- <g id="runner" transform="translate(18 142)">
- <circle class="runner" cx="0" cy="0" r="10"></circle>
- </g>
- </svg>
- </div>
- <div class="panel">
- <button class="play-btn" onclick="runDemo()">REPLAY</button>
- </div>
- </div>
- </div>
- <script src="../page_utils.js"></script>
- <script src="../../xjs.js"></script>
- <script>
- const path = document.getElementById('track');
- const runner = document.getElementById('runner');
-
- function runDemo() {
- const len = path.getTotalLength();
- xjs({ p: 0 }).animate({
- p: [0, 1],
- duration: 1400,
- easing: 'ease-in-out',
- update: ({ progress }) => {
- const pt = path.getPointAtLength(len * progress);
- runner.setAttribute('transform', `translate(${pt.x} ${pt.y})`);
- }
- });
- }
-
- setTimeout(runDemo, 320);
- </script>
- </div>
- </body>
- </html>
|