Search code examples
google-chromeanimationlottieblurry

Chrome shows Lottie animation blurry


I have the issue with scaled Lottie animation that Chrome blurs the animation. This is especial visible when the animation is scaled.

In my example, the original Animation is 842x596px as smaller it gets renders as worse gets the result:

Screenshot blurry lottie animation compared chrome and firefox

Here is the example code, if you want to reproduce it in your Chrome Browser:

lottie-player {
  border: 1px solid lightblue;
}

body {
  color: lightgray;
}
<script src="https://unpkg.com/@lottiefiles/lottie-player@latest/dist/lottie-player.js"></script>

<!--
<lottie-player src="https://assets6.lottiefiles.com/packages/lf20_srq2xawa.json" background="transparent" speed="1" style="width: 300px; height: 300px;" loop controls autoplay></lottie-player>
300x300px 
-->
                    
<lottie-player src="https://assets6.lottiefiles.com/packages/lf20_srq2xawa.json" background="transparent" speed="1" style="width: 200px; height: 200px;" loop autoplay></lottie-player>
200x200px

<lottie-player src="https://assets6.lottiefiles.com/packages/lf20_srq2xawa.json" background="transparent" speed="1" style="width: 150px; height: 150px;" loop autoplay></lottie-player>
150x150px
 
 <lottie-player src="https://assets6.lottiefiles.com/packages/lf20_srq2xawa.json" background="transparent" speed="1" style="width: 100px; height: 100px;" loop autoplay></lottie-player>
100x100px
 
 <lottie-player src="https://assets6.lottiefiles.com/packages/lf20_srq2xawa.json" background="transparent" speed="1" style="width: 50px; height: 50px;" loop autoplay></lottie-player>
50x50px


It seems there are already other question which have a similar problem but don't provide further information or don't provide a working solution:


Solution

  • The issue is caused by the following style tag on the SVG inside the Lottie animation:

    svg source text with translate3d

    transform: translate3d(0px, 0px, 0px);
    

    The simplest solution is to remove this tag via JS:

    document.addEventListener("DOMContentLoaded", function(){
    
      let elements = document.getElementsByTagName('lottie-player');
    
      for (var i = 0; i < elements.length; i++) {
      
        elements[i].addEventListener('play', (event) => {
          // console.log(event.target.shadowRoot.querySelector('svg').style.transform);
          event.target.shadowRoot.querySelector('svg').style.transform = '';
        });
        elements[i].play(); // trigger (again)
    
      }
    });
    

    document.addEventListener("DOMContentLoaded", function(){
    
      let elements = document.getElementsByTagName('lottie-player');
    
      for (var i = 0; i < elements.length; i++) {
      
        elements[i].addEventListener('play', (event) => {
          // console.log(event.target.shadowRoot.querySelector('svg').style.transform);
          event.target.shadowRoot.querySelector('svg').style.transform = '';
        });
      
      }
    
    });
    lottie-player {
      border: 1px solid lightblue;
    }
    
    body {
      color: lightgray;
    }
    <script src="https://unpkg.com/@lottiefiles/lottie-player@latest/dist/lottie-player.js"></script>
    
    <!--
    <lottie-player src="https://assets6.lottiefiles.com/packages/lf20_srq2xawa.json" background="transparent" speed="1" style="width: 300px; height: 300px;" loop controls autoplay></lottie-player>
    300x300px 
    -->
                        
    <lottie-player src="https://assets6.lottiefiles.com/packages/lf20_srq2xawa.json" background="transparent" speed="1" style="width: 200px; height: 200px;" loop autoplay></lottie-player>
    200x200px
    
    <lottie-player src="https://assets6.lottiefiles.com/packages/lf20_srq2xawa.json" background="transparent" speed="1" style="width: 150px; height: 150px;" loop autoplay></lottie-player>
    150x150px
     
     <lottie-player src="https://assets6.lottiefiles.com/packages/lf20_srq2xawa.json" background="transparent" speed="1" style="width: 100px; height: 100px;" loop autoplay></lottie-player>
    100x100px
     
     <lottie-player src="https://assets6.lottiefiles.com/packages/lf20_srq2xawa.json" background="transparent" speed="1" style="width: 50px; height: 50px;" loop autoplay></lottie-player>
    50x50px