svg+js实现儿童卡通交互有声动画片制作代码

代码语言:html

所属分类:其他

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

代码描述:svg+js实现儿童卡通交互有声动画片制作代码

代码标签: svg+js 儿童 卡通 交互 有声 动画片 制作 代码

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

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>帮小兔找回胡萝卜 - 儿童互动卡通</title>
<style>
  * {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
  }
  html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: linear-gradient(135deg, #dff6ff 0%, #fff4d9 100%);
    font-family: 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'Comic Sans MS', sans-serif;
  }

  #app {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
  }

  #stage-wrapper {
    position: relative;
    width: 100%;
    max-width: 1180px;
    aspect-ratio: 16 / 10;
    max-height: calc(100vh - 24px);
    background: #87cefa;
    border-radius: 28px;
    border: 6px solid #ffffff;
    box-shadow: 0 18px 45px rgba(45, 95, 138, 0.22), 0 0 0 4px #ffd166;
    overflow: hidden;
  }

  #stage {
    width: 100%;
    height: 100%;
    display: block;
    touch-action: none;
  }

  /* 暂停时冻结CSS动画 */
  .paused * {
    animation-play-state: paused !important;
  }

  /* 顶部进度条 */
  .top-hud {
    position: absolute;
    top: 14px;
    left: 16px;
    right: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    pointer-events: none;
    z-index: 20;
  }

  .progress-pill {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.92);
    border: 3px solid #ffb703;
    border-radius: 999px;
    padding: 6px 14px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.12);
    pointer-events: auto;
  }
  .carrot-dot {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #ffe8cc;
    border: 2px solid #f4a261;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.3s;
    opacity: 0.55;
  }
  .carrot-dot.done {
    background: #ffd166;
    border-color: #f77f00;
    opacity: 1;
    transform: scale(1.15);
  }
  .carrot-dot.current {
    background: #fff3b0;
    border-color: #ff6b6b;
    opacity: 1;
    animation: dotPulse 1.4s ease-in-out infinite;
  }

  /* 右上角控制按钮组 (儿童大按钮) */
  .controls {
    display: flex;
    gap: 10px;
    pointer-events: auto;
  }

  .ctrl-btn {
    min-width: 58px;
    height: 54px;
    padding: 0 14px;
    border-radius: 20px;
    border: 3px solid #ffffff;
    background: #ff9f1c;
    color: #ffffff;
    font-size: 18px;
    font-weight: 800;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    box-shadow: 0 5px 0 #d97706, 0 8px 16px rgba(0,0,0,0.18);
    transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.2s;
  }
  .ctrl-btn:hover { transform: translateY(-2px); }
  .ctrl-btn:active {
    transform: translateY(3px);
    box-shadow: 0 2px 0 #d97706, 0 4px 8px rgba(0,0,0,0.15);
  }
  .ctrl-btn.blue {
    background: #2ec4b6;
    box-shadow: 0 5px 0 #0f968a, 0 8px 16px rgba(0,0,0,0.18);
  }
  .ctrl-btn.blue:active { box-shadow: 0 2px 0 #0f968a; }
  .ctrl-btn.pink {
    background: #ff6b6b;
    box-shadow: 0 5px 0 #d64545, 0 8px 16px rgba(0,0,0,0.18);
  }
  .ctrl-btn.pink:active { box-shadow: 0 2px 0 #d64545; }
  .ctrl-btn.muted {
    background: #94a3b8;
    box-shadow: 0 5px 0 #64748b;
  }

  /* 底部大字幕条 */
  .subtitle-bar {
    position: absolute;
    bottom: 14px;
    left: 50%;
    transform: translateX(-50%);
    width: min(92%, 880px);
    background: rgba(255, 255, 255, 0.94);
    border: 4px solid #4cc9f0;
    border-radius: 26px;
    padding: 12px 24px;
    text-align: center;
    font-size: clamp(16px, 2.3vw, 24px);
    font-weight: 800;
    color: #2b2d42;
    line-height: 1.4;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    z-index: 20;
    pointer-events: none;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), border-color 0.3s;
  }
  .subtitle-bar.celebrate {
    border-color: #ff9f1c;
    background: #fffbeb;
    transform: translateX(-50%) scale(1.04);
  }

  /* 封面 & 暂停 & 结束浮层 */
  .overlay {
    position: absolute;
    inset: 0;
    background: rgba(25, 45, 75, 0.42);
    backdrop-filter: blur(4px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 30;
    padding: 20px;
    text-align: center;
    transition: opacity 0.35s ease;
  }
  .overlay.hidden {
    opacity: 0;
    pointer-events: none;
  }

  .card {
    background: #fffdf5;
    border: 6px solid #ffd166;
    border-radius: 36px;
    padding: 28px 40px;
    max-width: 560px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.28);
    animation: popIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
  }
  .card h1 {
    margin: 0 0 10px 0;
    font-size: clamp(26px, 4vw, 40px);
    color: #e76f51;
    text-shadow: 2px 2px 0 #ffe5d9;
  }
  .card p {
    margin: 0 0 24px 0;
    font-size: clamp(16px, 2vw, 21px);
    color: #4a5568;
    font-weight: 600;
    line-height: 1.5;
  }

  .big-play-btn {
    padding: 16px 42px;
    font-size: clamp(22px, 3vw, 28px);
    font-weight: 900;
    color: #ffffff;
    background: linear-gradient(180deg, #ff7b54 0%, #f7592b 100%);
    border: 4px solid #ffffff;
    border-radius: 999px;
    cursor: pointer;
    box-shadow: 0 8px 0 #c93b14, 0 14px 25px rgba(247, 89, 43, 0.4);
    transition: transform 0.15s ease;
    animation: bigBounce 1.8s ease-in-out infinite;
  }
  .big-play-btn:hover { transform: scale(1.05); }
  .big-play-btn:active { transform: translateY(4px); box-shadow: 0 4px 0 #c93b14; }

  /* SVG 内部动画样式 */
  @keyframes dotPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.18); }
  }
  @keyframes popIn {
    0% { transform: scale(0.75); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
  }
  @keyframes bigBounce {
    0%, 100% { transform: translateY(0) scale(1); }
    50% { transform: translateY(-6px) scale(1.03); }
  }
  @keyframes floatSlow {
    0%, 100% { transform: translateY(0px); }
    50% { transform: translateY(-8px); }
  }
  @keyframes cloudDrift {
    0% { transform: translateX(-30px); }
    50% { transform: translateX(30px); }
    100% { transform: translateX(-30px); }
  }
  @keyframes sunSpin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
  }
  @keyframes bunnyBreath {
    0%, 100% { transform: scaleY(1) translateY(0); }
    50% { transform: scaleY(1.025) translateY(-3px); }
  }
  @keyframes bunnyHop {
    0%, 100% { transform: translateY(0) scale(1, 1); }
    25% { transform: translateY(-28px) scale(0.96, 1.05); }
    50% { transform: translateY(0) scale(1.06, 0.94); }
    75% { transform: translateY(-16px) scale(0.98, 1.03); }
  }
  @keyframes earWiggle {
    0%, 100% { transform: rotate(0deg); }
    50% { transform: rotate(6deg); }
  }
  @keyframes bushWiggle {
    0%, 100% { transform: rotate(0deg); }
    20% { transform: rotate(-5deg); }
    40% { transform: rotate(5deg); }
    60% { transform: rotate(-3deg); }
    80% { transform: rotate(3deg); }
  }
  @keyframes pulseRing {
    0% { transform: scale(0.92); opacity: 0.85; }
    50% { transform: scale(1.1); opacity: 0.35; }
    100% { transform: scale(0.92); opacity: 0.85; }
  }
  @keyframes wrongShake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-14px) rotate(-4deg); }
    40% { transform: translateX(14px) rotate(4deg); }
    60% { transform: translateX(-10px) rotate(-2deg); }
    80% { transform: translateX(10px) rotate(2deg); }
  }
  @keyframes waterWave {
    0%, 100% { transform: translateX(0); }
    50% { transform: translateX(18px); }
  }

  .sun-rays { transform-origin: 1060px 105px; animation: sunSpin 26s linear infinite; }
  .cloud-1 { animation: cloudDrift 16s ease-in-out infinite; }
  .cloud-2 { animation: cloudDrift 22s ease-in-out infinite reverse; }
  .river-wave { animation: waterWave 3.5s ease-in-out infinite; }

  .bunny-idle { transform-origin: center bottom; animation: bunnyBreath 2.2s ease-in-out infinite; }
  .bunny-cheer { transform-origin: center bottom; animation: bunnyHop 0.75s cubic-bezier(0.34, 1.56, 0.64, 1) infinite; }
  .ear-left { transform-origin: 0px -75px; animation: earWiggle 2.8s ease-in-out infinite; }
  .ear-right { transform-origin: 36px -75px; animation: earWiggle 2.8s ease-in-out infinite reverse; }

  .interactive-item {
    cursor: pointer;
    transition: opacity 0.35s ease, filter 0.3s ease;
  }
  .interactive-item.floaty {
    animation: floatSlow 2.1s ease-in-out infinite;
  }
  .interactive-item.wiggle-clue {
    animation: bushWiggle 1.6s ease-in-out infinite;
  }
  .interactive-item.wrong-anim {
    animation: wrongShake 0.48s ease-in-out;
  }
  .interactive-item.dimmed {
    opacity: 0.38;
  }

  .hint-halo {
    fill: none;
    stroke: #ffd166;
    stroke-width: 8;
    stroke-dasharray: 16 10;
    opacity: 0;
    pointer-events: none;
    transform-box: fill-box;
    transform-origin: center;
  }
  .show-halo .hint-halo {
    opacity: 0.95;
    animation: pulseRing 1.4s ease-in-out infinite;
  }
  .hint-strong .hint-halo {
    stroke: #ff595e;
    stroke-width: 11;
    opacity: 1;
    animation: pulseRing 0.85s ease-in-out infinite;
  }

  /* 交互锁定状态 */
  .locked-stage #interactive-layer {
    pointer-events: none;
  }

  @media (max-width: 680px) {
    .ctrl-btn { min-width: 44px; height: 44px; padding: 0 10px; font-size: 14px; border-radius: 14px; }
    .carrot-dot { width: 18px; height: 18px; font-size: 11px; }
    .progress-pill { gap: 4px; padding: 4px 10px; }
    .subtitle-bar { padding: 8px 14px; bottom: 8px; border-width: 3px; }
  }
</style>
</head>
<body>
<div id="app">
  <div id="stage-wrapper" class.........完整代码请登录后点击上方下载按钮下载查看

网友评论0