logo

F2

  • 教程
  • 组件API
  • 图表示例
  • 所有产品antv logo arrow
  • 5.10.0
  • 快速上手
  • 核心概念
  • 图形语法
  • 数据处理
  • 度量
  • 坐标系
  • 图形标签 - Shape
  • 绘图属性 - Style
  • 动画属性 - Animation
  • 事件属性 - Event
  • 图形使用 - JSX
  • 自定义组件
  • 多端/框架 - Framework
    • 多端适配
    • 如何在 React 中使用
    • 如何在 Vue 中使用
    • 如何在小程序中使用
    • 如何在 Node.js 中使用
    • 配置 JSX Transform
    • 使用 SVG 渲染
  • 进阶 - Advanced
    • 自定义 View
  • 常见问题 - Question
    • 和 React 同时使用时,TS 类型报错

动画属性 - Animation

上一篇
绘图属性 - Style
下一篇
事件属性 - Event

资源

Ant Design
Galacea Effects
Umi-React 应用开发框架
Dumi-组件/文档研发工具
ahooks-React Hooks 库
WeaveFox-前端智能研发

社区

体验科技专栏
seeconfSEE Conf-蚂蚁体验科技大会
weavefoxWeaveFox-智能研发技术社区

帮助

GitHub
StackOverflow

more products更多产品

Ant DesignAnt Design-企业级 UI 设计语言
yuque语雀-知识创作与分享工具
EggEgg-企业级 Node 开发框架
kitchenKitchen-Sketch 工具集
GalaceanGalacean-互动图形解决方案
weavefoxWeaveFox-前端智能研发
© Copyright 2026 Ant Group Co., Ltd..备案号:京ICP备15032932号-38

Loading...

F2 动画定义与 Web Animations API 靠齐,除了组件层面,每个图形标签也都可以添加自定义动画。目前只支持基于 Keyframe 的动画,可定义动画执行阶段,以及变化效果 KeyframeEffect。

动画执行阶段

动画执行阶段分为 appear、update 以及 leave:

阶段说明触发时机
appear初始化时的入场动画render 阶段
update数据更新时的更新动画props 发生改变
leave销毁前的离场动画destroy 阶段

每个阶段都可以配置相应的 animation。

Animation 属性

基础属性

属性类型默认值描述
easingstring'linear'缓动函数,动画持续效果
durationnumber-动画持续时间(毫秒)
delaynumber0开始动画前的延迟(毫秒)
fillstring'none'定义图形在动画执行前后的表现,可选值:'none'、'forwards'、'backwards'、'both'
iterationsnumber1循环次数,Infinity 为无限循环
iterationStartnumber0从何处执行动画
propertystring[]-声明需要变换的属性
startKeyframe-开始帧状态
endKeyframe-结束帧状态
clipClip-裁剪区域动画,见裁剪

easing 缓动函数

缓动函数,默认为 linear,并且内置提供以下缓动函数,可参考效果:

恒速加速减速加速-减速减速-加速
linearease-in / inease-out / outease-in-out / in-outease-out-in / out-in
easein-sineout-sinein-out-sineout-in-sine
stepsin-quadout-quadin-out-quadout-in-quad
step-startin-cubicout-cubicin-out-cubicout-in-cubic
step-endin-quartout-quartin-out-quartout-in-quart
-in-quintout-quintin-out-quintout-in-quint
-in-expoout-expoin-out-expoout-in-expo
-in-circout-circin-out-circout-in-circ
-in-backout-backin-out-backout-in-back
-in-bounceout-bouncein-out-bounceout-in-bounce
-in-elasticout-elasticin-out-elasticout-in-elastic
-spring / spring-inspring-outspring-in-outspring-out-in

Keyframe 支持的属性

目前支持变换的属性:

属性类型说明
transformstring和 CSS Transform 保持一致
opacitynumber透明度
strokeOpacitynumber描边透明度
fillstring填充色
strokestring描边色
lineWidthnumber线宽
rnumberCircle 的半径
rxnumberEllipse 的 x 半径
rynumberEllipse 的 y 半径
widthnumberRect/Image 的宽度
heightnumberRect/Image 的高度
xnumber位置 x 坐标
ynumber位置 y 坐标
x1numberLine 的起点 x 坐标
y1numberLine 的起点 y 坐标
x2numberLine 的终点 x 坐标
y2numberLine 的终点 y 坐标
offsetDistancenumber路径偏移,和 CSS Offset 保持一致
lineDashnumber[]实线和间隔的长度
lineDashOffsetnumber虚线的偏移量,可实现蚂蚁线效果
pathstringPath 的定义,可做形变动画

基础用法

入场动画

<text
style={{
text: '测试',
x: 100,
y: 100,
}}
animation={{
appear: {
easing: 'linear',
duration: 450,
property: ['x', 'y'],
start: {
x: 0,
y: 0,
},
end: {
x: 100,
y: 100,
},
},
}}
/>

更新动画

<rect
style={{
x: 100,
y: 100,
width: 50,
height: 50,
fill: 'blue',
}}
animation={{
appear: {
easing: 'linear',
duration: 450,
property: ['width', 'height'],
start: {
width: 0,
height: 0,
},
end: {
width: 50,
height: 50,
},
},
update: {
easing: 'ease-in-out',
duration: 300,
property: ['fill'],
start: {
fill: 'blue',
},
end: {
fill: 'red',
},
},
}}
/>

离场动画

<circle
style={{
cx: 100,
cy: 100,
r: 50,
fill: 'green',
}}
animation={{
leave: {
easing: 'ease-out',
duration: 500,
property: ['opacity', 'r'],
start: {
opacity: 1,
r: 50,
},
end: {
opacity: 0,
r: 0,
},
},
}}
/>

多属性动画

<rect
style={{
x: 50,
y: 50,
width: 100,
height: 100,
fill: '#1890ff',
}}
animation={{
appear: {
easing: 'ease-in-out',
duration: 1000,
property: ['x', 'y', 'width', 'height', 'opacity'],
start: {
x: 100,
y: 100,
width: 0,
height: 0,
opacity: 0,
},
end: {
x: 50,
y: 50,
width: 100,
height: 100,
opacity: 1,
},
},
}}
/>

变换动画

<rect
style={{
x: 100,
y: 100,
width: 50,
height: 50,
fill: 'red',
transformOrigin: 'center',
}}
animation={{
appear: {
easing: 'linear',
duration: 2000,
property: ['transform'],
start: {
transform: 'rotate(0deg) scale(1)',
},
end: {
transform: 'rotate(360deg) scale(1.5)',
},
},
}}
/>

裁剪动画

<text
style={{
text: '裁剪动画',
x: 100,
y: 100,
}}
animation={{
appear: {
easing: 'linear',
duration: 1000,
clip: {
type: 'rect',
property: ['width'],
style: {
x: 100,
y: 100,
height: 20,
},
start: {
width: 0,
},
end: {
width: 100,
},
},
},
}}
/>

循环动画

<circle
style={{
cx: 100,
cy: 100,
r: 30,
fill: 'blue',
}}
animation={{
appear: {
easing: 'ease-in-out',
duration: 1000,
iterations: Infinity, // 无限循环
property: ['r'],
start: {
r: 20,
},
end: {
r: 40,
},
},
}}
/>

延迟动画

<rect
style={{
x: 100,
y: 100,
width: 50,
height: 50,
fill: 'green',
}}
animation={{
appear: {
easing: 'linear',
duration: 500,
delay: 1000, // 延迟 1 秒开始
property: ['opacity'],
start: {
opacity: 0,
},
end: {
opacity: 1,
},
},
}}
/>

路径动画

让图形沿着某个路径移动,在 CSS 中可通过 MotionPath 实现,F2 可通过图形标签上设置 offset 属性实现,目前支持 <line/> 和 <polyline/>。

基础路径动画

<circle
style={{
fill: '#808080',
r: 10,
offset: {
type: 'polyline',
style: {
points: [
[0, 3],
[50, 10],
[130, 80],
[250, 40],
],
},
},
}}
animation={{
appear: {
easing: 'ease-out',
duration: 1000,
property: ['offsetDistance'],
start: {
offsetDistance: 0,
},
end: {
offsetDistance: 1,
},
},
}}
/>

Line 组件路径动画

F2 在组件 Line 中内置了该功能,提供 endView 接口,可设置沿着线段移动的元素,具体可见 demo。

TypeScript 类型定义

interface Animation {
appear?: AnimationConfig
update?: AnimationConfig | AnimationConfig[]
leave?: AnimationConfig
}
interface AnimationConfig {
easing?: string
duration?: number
delay?: number
fill?: 'none' | 'forwards' | 'backwards' | 'both'
iterations?: number
iterationStart?: number
property?: string[]
start?: Keyframe
end?: Keyframe
clip?: ClipAnimation
}
interface Keyframe {
transform?: string
opacity?: number
strokeOpacity?: number
fill?: string
stroke?: string
lineWidth?: number
r?: number
rx?: number
ry?: number
width?: number
height?: number
x?: number
y?: number
x1?: number
y1?: number
x2?: number
y2?: number
offsetDistance?: number
lineDash?: number[]
lineDashOffset?: number
path?: string
}
interface ClipAnimation {
type: 'circle' | 'rect' | 'polygon'
property?: string[]
style: Record<string, any>
start?: Record<string, any>
end?: Record<string, any>
}

常见问题

如何让动画无限循环?

设置 iterations: Infinity:

animation={{
appear: {
easing: 'linear',
duration: 2000,
iterations: Infinity,
property: ['opacity'],
start: { opacity: 0 },
end: { opacity: 1 },
},
}}

如何让动画结束时保持最终状态?

设置 fill: 'forwards':

animation={{
appear: {
easing: 'linear',
duration: 1000,
fill: 'forwards',
property: ['x'],
start: { x: 0 },
end: { x: 100 },
},
}}

如何创建弹簧动画效果?

使用 spring 系列缓动函数:

animation={{
appear: {
easing: 'spring',
duration: 1000,
property: ['x'],
start: { x: 0 },
end: { x: 100 },
},
}}

如何同时动画多个属性?

在 property 数组中声明多个属性:

animation={{
appear: {
easing: 'ease-in-out',
duration: 1000,
property: ['x', 'y', 'width', 'height', 'opacity'],
start: {
x: 100,
y: 100,
width: 0,
height: 0,
opacity: 0,
},
end: {
x: 50,
y: 50,
width: 100,
height: 100,
opacity: 1,
},
},
}}

相关文档

  • 图形标签
  • 绘图属性
  • 图形事件
  • 图形使用