Adobe Animate.cc 2017的SnapSVG扩展能够为web创建交互性和动画。我目前正在尝试在我的REACT JS WebApplication中使用导出的SnapSVG Adobe Animate.cc项目。
到目前为止我所做的,
代码
import axios from 'axios';
import snapsvg from 'snapsvg';
import { SVGAnim } from './SnapSVGAnimator.min.js';
let jsonfile = "circle.json",
responseType: 'json';
componentDidMount(){
axios.get(jsonfile)
.then(response => {
const json = response.request.responseText;
const animatedSVG = new SVGAnim(json);
});
}
Problem
当导入到JSX文件中时,SnapSVGAnimator.min.js会产生警告和错误。看起来在编译这些代码时出了点问题。
✖1557问题(110个错误,1447个警告)
发布于 2019-06-06 02:38:45
首先,安装以下库:
npm install --save snapsvg-animator snapsvg-cjs
假设您的json位于../../public/myAnimation.json,请执行以下操作:
import React, { useEffect } from 'react';
import SVGAnim from "snapsvg-animator";
import "snapsvg-cjs";
const myAnimation = require('../../public/myAnimation.json'); //import your json
function Home() {
const svg = new SVGAnim(
myAnimation,
200, //width
220, //height
40 //fps
);
useEffect(() => {
const container = document.getElementById('animation');
container.appendChild(svg.s.node);
});
return (
<div id="main">
<div id="animation"/>
</div>
)
};
export default Home;
我之所以使用react钩子,是因为它是非常流行的☺,但它同样适用于"render“和”render“。
https://stackoverflow.com/questions/45678310
复制相似问题