react项目中使用lottie动画
一,引入lottie库
点击查看代码
npm i --save react-lottie @types/react-lottie
二,下载lottie的json文件
去iconfont.cn中可以在库中下载lottie文件(注意版权问题)
三,在项目中使用lottie
点击查看代码
import * as React from "react";
import Lottie from "react-lottie";
import * as myLottie from "../../assets/lottie.json";
export interface HelloProps {
compiler: string;
framework: string;
}
// 'HelloProps' describes the shape of props.
// State is never set so we use the '{}' type.
export class Hello extends React.Component<HelloProps, {}> {
render() {
const options = {
loop: true,
autoplay: true,
animationData: myLottie,
rendererSettings: {
preserveAspectRatio: "xMidYMid slice",
},
};
return (
<div>
<h1>
Hello from {this.props.compiler} and {this.props.framework}!
</h1>
<Lottie options={options} height={100} width={100} />
</div>
);
}
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!