H5 中使用SVGA 动画

一、html有支持SVG的标签,但是不支持SVGA 

二、怎么做?

用的是开源的 https://gitcode.net/mirrors/svga/SVGAPlayer-Web/-/blob/master/README.zh.mdhttps://gitcode.net/mirrors/svga/SVGAPlayer-Web/-/blob/master/README.zh.md有说明的,下面是我的代码。

<!DOCTYPE HTML>

<html>

<head>

<title>动画</title>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    <style>

        #box{margin: 0px;   padding: 0px; border: 1px violet solid; }

        #ssss{ width: 100vh;  height: 100vh;  }

        #demoCanvas{  width: 300px;  height: 300px;  margin: 0 auto;  border: 1px salmon solid;}

    </style>

<script src="https://cdn.jsdelivr.net/npm/svgaplayerweb@2.3.1/build/svga.min.js"></script>

</head>

<body id="box">

<div id="ssss" >

<button οnclick="givGift()">出现动画</button>

<button οnclick="stopAnimation()">停止播放动画</button>

<div id="demoCanvas" ></div>

</div>

<script>

var player = new SVGA.Player('#demoCanvas');

player.loops=1;

player.clearsAfterStop=true;

var parser = new SVGA.Parser('#demoCanvas'); // 如果你需要支持 IE6+,那么必须把同样的选择器传给 Parser。

function givGift(){

    parser.load('applause.svga', function(videoItem) {

    player.setVideoItem(videoItem);

    player.startAnimation();

    player.onFinished(function(){

    });

})

}

</script>

</body>

</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值