lottie - 在lottie json中动态更改颜色
问题描述
我使用Lottie-web制作了 Lottie 动画,现在尝试动态更改颜色,因此我使用了Lottie API ( https://github.com/bodymovin/lottie-api )。在那,我得到了改变颜色的 keyPath,但不知道如何改变对象的颜色。
这是创建lottie对象动画的代码
var animData = {
container: animationContainer,
renderer: "canvas",
loop: true,
autoplay: true,
rendererSettings: {
preserveAspectRatio: "xMidYMid meet"
},
path: "https://labs.nearpod.com/bodymovin/demo/chameleon/chameleon2.json"
};
anim = lottie.loadAnimation(animData);
用于更改我使用的 Lottie JSON 的颜色
animationAPI.getKeyPath(
"#leaf_3,Contents,color_group,fill_prop,Color"
);
我得到了一个对象的路径,但现在我不知道如何改变颜色,所以如果有人知道,请帮助我?
解决方案
您可以使用lottie-colorify
包来更改动画颜色:
const animation = Lottie.loadAnimation({
container: container.current,
animationData: colorify(['#ef32d0', [50, 100, 200], '#fe0088'], SomeAnimation),
});
推荐阅读
- ruby - Dokku:部署、构建和服务中间人静态生成的网站
- python - UnicodeDecodeError - 将编码添加到自定义函数输入
- laravel - Laravel PDF 孟加拉字体不支持
- python - 是否有更短的方法来添加列表的每个项目
- c - 用 C 编写递归函数的问题(数字中的数字顺序)
- php - 使用 jQuery 从数据库中删除
- angular - Angular mat-form-filed 未找到“ngForm”
- arrays - 如何在 Thinkscript 中创建一个数组(IDataHolder)?(思考游泳)
- java - 如何启用在 Eclipse 上显示功能解释?
- swift - 如何在 Swift 中将 TimeDelay 设置为第二天@凌晨 5 点?