You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using @lottiefiles/dotlottie-web, calling play() after setFrame() resets the currentFrame property and restarts the animation from the start. This does not match the documentation for play(): Begins playback from the current animation position.
import{DotLottie}from"https://cdn.jsdelivr.net/npm/@lottiefiles/dotlottie-web/+esm";(()=>{// Get lottie player and set the animation to play from half way through when finished a loopconstcanvas=document.getElementById('hero-lottie');constplayer=newDotLottie({autoplay: true,loop: false,canvas: canvas,speed: 1,src: canvas.getAttribute('data-src'),});// Get loopFrom attributeconstloopFrom=parseInt(canvas.getAttribute('loopFrom'));player.addEventListener('complete',()=>{player.setFrame(loopFrom);player.play();// Here the animation resets to the frame 0});})();
A workaround is to call player.setFrame() after play().
The text was updated successfully, but these errors were encountered:
Rapsssito
changed the title
play() resets after setFrame() resets the animationplay() after setFrame() resets the animation
Apr 12, 2024
Thank you, @Rapsssito, for bringing up this issue, will address it in future releases.
But If you're looking to loop through a specific part of the animation, say from loopFrom to the end of the animation, you might consider using the setSegment method. Here's how you can implement it:
import{DotLottie}from"https://cdn.jsdelivr.net/npm/@lottiefiles/dotlottie-web/+esm";(()=>{constcanvas=document.getElementById('hero-lottie');constplayer=newDotLottie({autoplay: false,// ensure autoplay is false, so the player doesn't start rendering on load loop: true,// ensure loop is set to truecanvas: canvas,speed: 1,src: canvas.getAttribute('data-src'),});constloopFrom=parseInt(canvas.getAttribute('loopFrom'));player.addEventListener("load",()=>{// Set the animation segment to play from 'loopFrom' to the last frameplayer.setSegment(loopFrom,player.totalFrames);// Start playing the animationplayer.play();});})();
Overview
Using
@lottiefiles/dotlottie-web
, callingplay()
aftersetFrame()
resets thecurrentFrame
property and restarts the animation from the start. This does not match the documentation forplay()
: Begins playback from the current animation position.A workaround is to call
player.setFrame()
afterplay()
.The text was updated successfully, but these errors were encountered: