简体   繁体   English

如何用按钮控制乐天 animation

[英]How to control a lottie animation with buttons

I've been trying to control a Lottie animation with buttons, I need the first button to take me to the start of the animation, the second to the middle, the third to later and so on.我一直在尝试用按钮控制 Lottie animation,我需要第一个按钮将我带到 animation 的开头,第二个到中间,第三个到后面等等。 The animation that I have downloaded for testing is with markers that I am trying to access and go to that frame in the animation, but I can not do it.我已经下载用于测试的 animation 带有我试图访问的标记和 go 到 animation 中的该帧,但我做不到。 The animation must also be controlled with scroll forward or backward. animation 还必须通过向前或向后滚动来控制。

Only the START button works at the moment.目前只有 START 按钮有效。

 LottieInteractivity.create({ mode:"scroll", player:'#vpfxlbmm', actions: [ { visibility:[0,1], type: "seek", frames: [0, 300], }, ] }); let player = document.querySelector("lottie-player"); let play = document.querySelector(".start"); let year1980 = document.querySelector(".year1980"); let year1990 = document.querySelector(".year1990"); let year2002 = document.querySelector(".year2002"); let stop = document.querySelector(".stop"); play.onclick = function () { player.play(); }; year1980.onclick = function () { //"progress" is the marker in animation player.goToAndPause("progress"); }; stop.onclick = function () { player.stop(); };
 <script src="https://unpkg.com/@lottiefiles/lottie-interactivity@latest/dist/lottie-interactivity.min.js"></script> <script src="https://unpkg.com/@lottiefiles/lottie-player@latest/dist/lottie-player.js"></script> <button class="start">Start</button> <button class="year1980">1980</button> <button class="year1990">1990</button> <button class="year2002">2002</button> <button class="stop">Stop</button>

 LottieInteractivity.create({ mode:"scroll", player:'#vpfxlbmm', actions: [ { visibility:[0,1], type: "seek", frames: [0, 300], }, ] }); let player = document.querySelector("lottie-player"); let play = document.querySelector(".start"); let year1980 = document.querySelector(".year1980"); let year1990 = document.querySelector(".year1990"); let year2002 = document.querySelector(".year2002"); let stop = document.querySelector(".stop"); play.onclick = function () { player.play(); }; year1980.onclick = function () { //"progress" is the marker in animation player.goToAndPause("progress"); }; stop.onclick = function () { player.stop(); };
 <script src="https://unpkg.com/@lottiefiles/lottie-interactivity@latest/dist/lottie-interactivity.min.js"></script> <script src="https://unpkg.com/@lottiefiles/lottie-player@latest/dist/lottie-player.js"></script> <button class="start">Start</button> <button class="year1980">1980</button> <button class="year1990">1990</button> <button class="year2002">2002</button> <button class="stop">Stop</button>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM