Skip to main content

动画

动画通过组件的 props.animations 声明式配置,由 ice.animationManager(每实例一个)驱动补间。

单段动画

const rect = new ICE.ICERect({
left: 100, top: 100, width: 80, height: 60,
animations: {
'transform.rotate': {
from: 0,
to: 360,
duration: 1000,
easing: 'out',
loop: true,
},
},
});
ice.addChild(rect);
ice.animationManager.add(rect);

配置项:

字段说明
from / to起止值;值是数组时逐元素补间
duration时长(ms),也可用 motion token:'fast'(100) / 'normal'(200) / 'slow'(300) / 'slower'(500)
delay延迟启动
easing缓动名(见下)
loop是否循环
iterationCount迭代次数
round是否取整(避免亚像素抖动)
keyframes关键帧时间轴(见下)

动画的 key 是点路径'transform.rotate''left''top' 等任意可补间的数值属性。

关键帧(keyframes)

animations: {
'left': {
duration: 1200,
keyframes: [
{ offset: 0, value: 0, easing: 'out' },
{ offset: 0.5, value: 300 },
{ offset: 1, value: 150, easing: 'inOut' },
],
},
}

每个关键帧用 offset(0~1)定位,可携带独立的 easing

缓动

缓动名说明
linear线性
out / inOut / outQuart经典缓动
spring / springSoft / springSnappy弹簧物理缓动(软/标准/干脆三档)

AnimationManager

ice.animationManager.add(component); // 参与动画(addChild 后需要)
ice.animationManager.remove(component);
ice.animationManager.start();
ice.animationManager.stop();
ice.animationManager.pause();
ice.animationManager.resume();
ice.animationManager.isPaused();

动画时长/缓动也可通过主题 motion token 统一管控。

示例:examples/animation/(basic / extended / keyframes / loop)与压测 examples/performance/animation-stress.html