Lottie-web: I would like to use an existing canvas.

Created on 25 May 2017  路  2Comments  路  Source: airbnb/lottie-web

I would like to use an existing canvas.

pug File

block content-block
  main
    .top
      canvas#top_anime

js File

const w = $('.top').width();
const h = $('.top').height();
$('#top_anime').attr('width', w);
$('#top_anime').attr('height', h);

bodymovin.loadAnimation({
    container: document.getElementById("top_anime"),
    renderer: "canvas",
    loop: false,
    autoplay: true,
    rendererSettings: {
        context: ('2d'),
        scaleMode: 'noScale',
        clearCanvas: true
    },
    path: '../bodymovin_anime/top.json'
});

After compiling
html

<main>
        <div class="top">
          <canvas id="top_anime">
            <canvas width="1500" height="1700" style="width: 100%; height: 100%; transform-origin: 0px 0px 0px;"></canvas>
          </canvas>

Please tell me how to solve it.

Most helpful comment

you need to get the canvas context
try something like:
```js var cvs = container: document.getElementById("top_anime"); var ctx = cvs.getContext('2d'); bodymovin.loadAnimation({ renderer: "canvas", loop: false, autoplay: true, rendererSettings: { context: ctx, scaleMode: 'noScale', clearCanvas: true }, path: '../bodymovin_anime/top.json' });

All 2 comments

you need to get the canvas context
try something like:
```js var cvs = container: document.getElementById("top_anime"); var ctx = cvs.getContext('2d'); bodymovin.loadAnimation({ renderer: "canvas", loop: false, autoplay: true, rendererSettings: { context: ctx, scaleMode: 'noScale', clearCanvas: true }, path: '../bodymovin_anime/top.json' });

Thank you for your continued support!!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ochanje210 picture ochanje210  路  3Comments

Ipaulsen picture Ipaulsen  路  4Comments

ritsraghani picture ritsraghani  路  3Comments

leantide picture leantide  路  3Comments

phileastv picture phileastv  路  3Comments