You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Framer Motion中让SVG的pathLength完全动画至0?

解决SVG路径动画结束后残留圆点的问题

问题根源在于strokeLinecap="round"属性:当pathLength动画到0时,SVG会为路径起点渲染一个与描边宽度一致的圆形端点,导致残留圆点。

只需给动画同步加上透明度变化,就能让路径在长度缩为0的同时完全透明,彻底消除残留点:

修改motion.path的animate配置,添加opacity属性:

<motion.path
  initial={{ pathLength: 1, opacity: 1 }}
  animate={{ 
    pathLength: showPassword ? 0 : 1,
    opacity: showPassword ? 0 : 1 // 同步透明度动画
  }}
  exit={{ pathLength: 1, opacity: 1 }}
  transition={{ duration: 0.2, ease: "easeInOut" }}
  strokeLinecap="round"
  strokeLinejoin="round"
  d="M3 3L21 21"
/>

动画过程中路径会随长度缩短逐渐透明,最终完全消失,视觉效果流畅自然。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.11 19:43:19