-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
autoplay and loop don't seem to work in svelte #246
Comments
Faced the same issue (using Svelte island on Astro), thanks for the workaround @rjwalters The problem seems to be with autoplay. (Edit: loop works on an Astro Island using Svelte, but not with Svelte alone) If anyone else has multiple animations to deal with, you can extract <script>
import { onMount } from 'svelte';
export let play = true;
export let loop = true;
export let mode = 'normal';
export let controls = false;
export let src;
let player;
onMount(async() => {
player.addEventListener('ready', () => {
if (play) player.play();
player.setLooping(loop);
});
});
</script>
<dotlottie-player bind:this={player}
src = {src}
mode = {mode}
controls = {controls}
worker = true
>
</dotlottie-player>
Edit: Just to add this issue was not there in version 1.4.2. |
Hi, I faced the same issues in Vue 3 project, the attributes were handled as prop instead of attribute, although the I don't know Svelte (yet) but I figured this out by "forcing" Vue to use attributes as they are, with <dotlottie-player src="/lottie/loader.lottie" :autoplay.attr="true" :loop.attr="true" /> |
Maybe some solutions for you in this article. |
@rjwalters We're investigating this issue. Thank you. @Djules Regarding the Vue usage, you can find a guide here that might help: https://docs.lottiefiles.com/dotlottie-players/components/player-component/usage/vue |
This fixed it,
|
Yes, @GregSharp-app - that's the current workaround. If you have multiple animations with different requirements for <script>
const setLottieConfig = (player, config) => {
Object.entries(config).forEach(([key, value]) => {
player.setAttribute(key, value);
});
};
</script>
<!--
setting autoplay, loop to false does not work,
don't include them at all if you want them to be false.
-->
<dotlottie-player
use:setLottieConfig = {{
autoplay: true,
loop: true,
mode: 'normal',
src: "...",
}}
/> This involves DOM manipulation, which might lead to some performance issues if you have a lot of animations. If you don't want to do DOM manipulation, you can make a component for <script>
import { onMount } from 'svelte';
export let play = true;
export let loop = true;
export let mode = 'normal';
export let controls = false;
export let src;
let player;
onMount(async() => {
player.addEventListener('ready', () => {
if (play) player.play();
player.setLooping(loop);
});
});
</script>
<dotlottie-player bind:this={player}
src = {src}
mode = {mode}
controls = {controls}
> |
I am trying to migrate from
@lottiefiles/lottie-player
but I am having trouble gettingautoplay
to work...if I include the controls, I am able to play and loop the lottie. A workaround is to trigger
play
when I receive the ready event:The text was updated successfully, but these errors were encountered: