Giter VIP home page Giter VIP logo

svgaplayer-wechat's Introduction

SVGAPlayer-WeChat

SVGAPlayer 在微信小程序中的实现,借助 SVGAPlayer,你可以在微信小程序中播放矢量动画,但有以下限制。

限制

位图动画不能播放

因为小程序的位图渲染能力相当弱,因此,位图动画被禁止使用。

矢量动画不能过于复杂

不能使用过于复杂的矢量动画,因为,过于复杂的矢量(矢量元素过多、效果太炫)会导致小程序卡死。

使用方法

下载源码

直接下载本仓库源码

转换 SVGA 文件至小程序兼容格式

  1. 将 svga 文件放置在 res 目录下
  2. 在命行令中,使用 node 执行 node script/converter.js 即可完成转换
  3. 将 *.wx.svga 文件放置在 HTTP 服务器

集成

将 svga 目录复制到你的工程目录下,然后在需要添加动画的地方,添加 canvas 组件。

在对应的 js 代码中,添加以下实现。

import SVGAPlayer from '../../svga/player'
import SVGAParser from '../../svga/parser'

Page({
  onLoad: function () {
    let player = new SVGAPlayer('canvas', 500, 500); // width = 500, height = 500, 对应的是 canvas 画布的大小。
    let parser = new SVGAParser();
    parser.load("http://yourserver.com/yourfile.wx.svga", (videoItem) => {
      player.setVideoItem(videoItem);
      player.startAnimation();
    });
  }
})
  • svga 文件需要放置在安全域名下

svgaplayer-wechat's People

Contributors

ponycui avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.