svga动画
程序员文章站
2022-03-02 19:44:37
...
var player = new SVGA.Player('#demoCanvas');
var parser = new SVGA.Parser('#demoCanvas'); // 如果你需要支持 IE6+,那么必须把同样的选择器传给Parser。
var svga = ''
var text1 = ''
var text2 = ''
var baifenbi = ''
if(type == 1){
svga = './js/svga/gtgs.svga'
text1 = '2201'
text2 = this.cunliangList[0].value
baifenbi = '20%'
}else if(type == 2){
svga = './js/svga/grdz.svga'
text1 = '5214'
text2 = this.cunliangList[1].value
baifenbi = '35%'
}else if(type == 3){
svga = './js/svga/hhqy.svga'
text1 = '4001'
text2 = this.cunliangList[2].value
baifenbi = '25%'
}else if(type == 4){
svga = './js/svga/qyfr.svga'
text1 = '1980'
text2 = this.cunliangList[3].value
baifenbi = '20%'
}
var datas = [{
text: {
text: text1,
family: 'not specified',
size: "24px",
color: "#fce911",
offset: {x: 90, y: 1}
},
name: 'img_305'
}, {
text: {
text: text2,
family: 'not specified',
size: "24px",
color: "#02FAFD",
offset: {x: 90, y: 1}
},
name: 'img_304'
}, {
text: {
text: baifenbi,
family: 'not specified',
size: "24px",
color: "#4A90E2",
offset: {x: 100, y: 1}
},
name: 'img_319'
}]
parser.load(svga, function (videoItem) {
player.loops = 1;
player.clearsAfterStop = false
player.setVideoItem(videoItem);
for (let i = 0; i < datas.length; i++) {
player.setText(datas[i].text, datas[i].name); // 可自定义文本样式
}
// player.setImage('./img/daping/ab.png', 'img_226');
player.startAnimation();
})
$('#demoCanvas').show()
<div class="svga" clearsAfterStop="false" loops="1" id="demoCanvas"></div>