React使用lottie-web前端动画


import React, { useEffect, useRef, useState } from 'react';
import lottie from 'lottie-web';

const Animation = props => {
    const { renderer, loop, path, canvasStyle }  = props;

    const lottieRef = useRef(null);
    const [, setLottie] = useState(null);
    useEffect(() => {
        setLottie(
            lottie.loadAnimation({
                container: lottieRef.current,
                // 渲染方式
                renderer,
                // autoplay 自动播放
                // 是否循环播放
                loop,
                // 路径
                path,
            })
        );
    }, []);
    return (
        <div>
            <div ref={lottieRef} className="lottie" style={canvasStyle}></div>
        </div>
    );
};
export default Animation;
     <Animation
         {...{
               renderer: 'svg',
               loop: true,
               path:`${BOS_STATIC_FILE_PREFIX}/adsImportLoading.json`,
               canvasStyle: { width: 300, hight: 300 },
         }}
     />

具体配置项见lottie-web - npm

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
React 360 是 Facebook 推出的一款基于 React 的 VR 开发框架,它能够让开发使用 React 组件化的思想来构建 VR 应用,并且不需要编写任何 WebGL 或者 Three.js 的代码。React 360 提供了一系列的组件和 API,可以帮助开发者构建出各种 VR 应用,如游戏、教育、演示等。 React 360 WebReact 360 的一种运行方式,可以将 VR 应用转化为 Web 应用,在浏览器中直接访问。使用 React 360 Web 开发 VR 应用,需要先安装 React 360 和 Node.js。 安装 React 360: ```bash npm install -g react-360-cli ``` 安装 Node.js:从官网 https://nodejs.org/en/ 下载并安装相应版本。 接下来,可以按照以下步骤使用 React 360 Web: 1. 创建项目 在终端中使用以下命令创建一个 React 360 Web 项目: ```bash react-360 init ProjectName ``` 其中,ProjectName 为项目名称。 2. 编写代码 React 360 Web开发方式与 React 开发 Web 应用的方式类似,需要在 index.js 文件中编写代码。以下是一个简单的例子: ```jsx import React from 'react'; import { AppRegistry, StyleSheet, Text, View, } from 'react-360'; export default class MyApp extends React.Component { render() { return ( <View style={styles.panel}> <Text style={styles.greeting}> Hello, React 360! </Text> </View> ); } }; const styles = StyleSheet.create({ panel: { width: 1000, height: 600, backgroundColor: 'rgba(255, 255, 255, 0.4)', justifyContent: 'center', alignItems: 'center', }, greeting: { fontSize: 30, fontWeight: 'bold', color: '#000', }, }); AppRegistry.registerComponent('MyApp', () => MyApp); ``` 3. 运行项目 在终端中使用以下命令运行项目: ```bash npm start ``` 运行成功后,会在浏览器中打开一个地址,例如: ``` http://localhost:8081/index.html ``` 在浏览器中访问该地址,即可看到 VR 应用。 以上是 React 360 Web 的简单使用方法,React 360 提供了丰富的组件和 API,可以满足各种 VR 应用的开发需求。具体的使用方法和 API 可以参考官方文档: https://facebook.github.io/react-360/docs/overview.html
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值