svg实现马儿奔跑动画代码

代码语言:html

所属分类:其他

代码由gemini-4-hydrogen ai生成,可能有错误,仅供参考:点击查看提示词

代码描述:svg实现马儿奔跑动画代码

代码标签: svg 马儿 奔跑 动画 代码

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>SVG 奔跑的骏马</title>
  <style>
    /* 全局可调参数:动画周期与滚动速度 */
    :root {
      --gallop-cycle-ms: 660;       /* 单个奔跑周期(毫秒),JS 会同步读取 */
      --far-hill-duration: 28s;     /* 远山视差滚动周期 */
      --mid-hill-duration: 11s;     /* 中景丘陵滚动周期 */
      --ground-scroll-duration: 1.85s; /* 近景草地与碎石滚动周期 */
      --bg-page: #121521;
    }

    * {
      box-sizing: border-box;
      margin: 0;
      padding: 0;
    }

    html,
    body {
      width: 100%;
      height: 100%;
      background: radial-gradient(circle at 50% 40%, #23283d 0%, var(--bg-page) 75%);
      display: grid;
      place-items: center;
      overflow: hidden;
      font-family: system-ui, -apple-system, sans-serif;
    }

    .stage {
      width: min(95vw, 1200px);
      max-height: 92vh;
      aspect-ratio: 900 / 500;
      border-radius: 18px;
      overflow: hidden;
      box-shadow:
        0 28px 70px rgba(0, 0, 0, 0.58),
        0 0 0 1px rgba(255, 224, 185, 0.12);
      background: #1b2236;
    }

    svg#scene {
      width: 100%;
      height: 100%;
      display: block;
    }

    /* 背景视差无缝向左滚动动画(基于双倍宽度的平铺图层) */
    .scroll-far {
      animation: scrollLeft900 var(--far-hill-duration) linear infinite;
      will-change: transform;
    }

    .scroll-mid {
      animation: scrollLeft900 var(--mid-hill-duration) linear infinite;
      will-change: transform;
    }

    .scroll-ground {
      animation: scrollLeft900 var(--ground-scroll-duration) linear infinite;
      will-change: transform;
    }

    /* 速度线向左高速飞掠 */
    .speed-line {
      transform-box: fill-box;
      animation: speedStreak 0.9s linear infinite;
      will-change: transform, opacity;
    }

    .speed-line.s1 { animation-duration: 0.72s; animation-delay: -0.15s; }
    .speed-line.s2 { animation-duration: 0.95s; animation-delay: -0.52s; }
    .speed-line.s3 { animation-duration: 0.64s; animation-delay: -0.34s; }
    .speed-line.s4 { animation-duration: 1.08s; animation-delay: -0.78s; }
    .speed-line.s5 { animation-duration: 0.80s; animation-delay: -0.60s; }

    /* 耳朵轻微的独立警觉微颤 */
    .ear-anim {
      transform-box: fill-box;
      transform-origin: 50% 92%;
      animation: earTwitch 1.9s ease-in-out infinite;
    }

    .ear-anim.back {
      animation-delay: -0.25s;
    }

    @keyframes scrollLeft900 {
      from { transform: translateX(0); }
      to   { transform: translateX(-900px); }
    }

    @keyframes speedStreak {
      0%   { transform: translateX(1050px); opacity: 0; }
      15%  { opacity: 0.55; }
      85%  { opacity: 0.55; }
      100% { transform: translateX(-320px); opacity: 0; }
    }

    @keyframes earTwitch {
      0%, 100% { transform: rotate(0deg); }
      30%      { transform: rotate(-5deg); }
      65%      { transform: rotate(4deg); }
    }
  </style>
</head>
<body>
  <div class="stage">
    <svg id="scene" viewBox="0 0 900 500" xmlns="http://www.w3.org/2000/svg" aria-label="奔跑的骏马 SVG 动画">
      <defs>
        <!-- 暮色草原天空渐变 -->
        <linearGradient id="skyGrad" x1="0" y1="0" x2="0" y2="1">
          <stop offset="0%"   stop-color="#19233c" />
          <stop offset="42%"  stop-color="#3c4f6e&quo.........完整代码请登录后点击上方下载按钮下载查看

网友评论0