You need to enable JavaScript to run this app. React Spring useTrail配置delay不生效 实现SVG三角串行缩放动画遇阻
优惠活动
大模型
产品
解决方案
定价
更多

React Spring useTrail配置delay不生效 实现SVG三角串行缩放动画遇阻

React-Spring 品牌Logo动效落地开发问题

开发背景

  • 当前应用全量动画体系基于react-spring搭建,团队动画开发经验储备不足
  • 设计师交付的品牌新Logo动效方案落地遇阻:该动效用原生JavaScript实现逻辑非常简单,但迁移到react-spring体系下始终无法顺利完成

已完成实现代码

import React from "react";
import { useTrail, animated } from "react-spring";

const Loader: React.FC = () => {
    // Animations
    const paths = [
        {
            id: 1,
            color: "#466FB5",
            d: "M90.6672 33H16L53.3336 96.4409L90.6672 33Z",
        },
        {
            id: 2,
            color: "#0093D3",
            d: "M53.3347 96.4443H128.002L90.6683 33.0034L53.3347 96.4443Z",
        },
        {
            id: 3,
            color: "#53BFA2",
            d: "M128.001 96.3701H53.3336L90.6672 159.811L128.001 96.3701Z",
        },
        {
            id: 4,
            color: "#93C83F",
            d: "M90.6675 159.892H165.335L128.001 96.4417L90.6675 159.892Z",
        },
        {
            id: 5,
            color: "#58B647",
            d: "M165.334 159.892H90.6664L128 223.333L165.334 159.892Z",
        },
        {
            id: 6,
            color: "#F2E90B",
            d: "M202.667 96.4436H128L165.334 159.894L202.667 96.4436Z",
        },
        {
            id: 7,
            color: "#FBB12C",
            d: "M128.001 96.4443H202.668L165.335 33.0034L128.001 96.4443Z",
        },
        {
            id: 8,
            color: "#FF5E8D",
            d: "M240 33H165.333L202.666 96.4409L240 33Z",
        },
    ];

    const trail = useTrail(paths.length, {
        from: {
            scale: 1,
        },
        to: async (next: any) => {
            while (1) {
                await next({ scale: 1.5 });
                await next({ scale: 1 });
            }
        },
    });

    return (
        <div style={{ width: "200px", height: "200px" }}>
            <svg
                width="72"
                height="72"
                viewBox="0 0 256 256"
                fill="none"
                xmlns="http://www.w3.org/2000/svg"
                style={{ overflow: "visible" }}>
                {trail.map(({ scale }, index) => {
                    const path = paths[index];
                    return (
                        <animated.path
                            key={path.id}
                            fill={path.color}
                            d={path.d}
                            style={{
                                transformOrigin: "center",
                                transform: scale.interpolate((s: any) => `scale(${s})`),
                            }}
                        />
                    );
                })}
            </svg>
        </div>
    );
};

现存核心问题

  • 串行缩放循环动画未生效:SVG画布内的每个三角形需要按顺序依次完成缩放循环动画,但反复调整useTrail配置始终无法实现串行触发逻辑
    • 此前尝试为useTrail添加动态延迟配置delay: (key: any) => key * 200,该配置完全未生效
    • 预期逻辑为前一个三角形走完完整动画周期后,再启动下一个三角形的动画
  • 设计对齐缺失:需要参照原动效设计实现对应的色彩切换效果,此前在react-spring技术社区发帖求助暂未得到有效回应

内容的提问来源于stack exchange,提问作者AlexanderKaran

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.11.21 11:15:04