Cannot make Lottie Interactivity work with Canvas element

Hi Folks!

I’m using this LottieFiles Interactivity guide to make my Lotties interactive on click, hover etc.

Lottie Player - Interactivity Guide

However, this approach uses the Lottie Web Player and I would like to use the Canvas element.

I’m using the following code to load the Lottie:

import { DotLottie } from "https://esm.sh/@lottiefiles/dotlottie-web";

const canvas = document.getElementById("lottie");

let dotLottie = new DotLottie({

autoplay: false,

loop: true,

mode: "forward",

speed: 1,

canvas,

src:

"https://assets.codepen.io/9400490/cycling.lottie"

});

and that displays the Lottie fine but when I try to add interactivity with the code below it is not working:

const player_2 = document.getElementById("lottie");

player_2.addEventListener("ready", () => {

LottieInteractivity.create({

player: player_2.getLottie(),

mode: "cursor",

actions: [

{

type: "hover",

forceFlag: false

}

]

});

});

Any help to get this work will be much appreciated!

Thanks!