Svga动画
2022-07-01 05:51:09
2025-01-11 14:44:33
官方文档
http
https://www.npmjs.com/package/svga.lite
安装命令
shell
npm i svga.lite -S
在需要的组件导入
js
import { Downloader, Parser, Player } from "svga.lite";
const downloader = new Downloader();
const parser = new Parser({ disableWorker: true });
视图
vue
<canvas
class="ticket"
id="canvas1"
v-show="showF"
\></canvas>
SVGA资源
放到imges.js文件
hxml
svgaAdree:"http://fstatic.cat1314.com/uc/svga/668fdef93df143447846793448d48cb4_1626786582.svga",
样式
css
.ticket{
width: 7.21rem;
height: 6.64rem;
}
方法
js
data() {
return {
showF: false,
};
},
js
mounted() {
this.svgaGo(this.images.svgaAdree);
}
js
methods: {
async svgaGo(adress) {
let canvas = document.getElementById("canvas1");
const fileData = await downloader.get(adress);
const data = await parser.do(fileData);
let player = new Player(canvas);
await player.mount(data);
player.start();
this.showF = true;
},
}
目录