Skip to content

Commit

Permalink
Dynamically fetch and play animation's last frame
Browse files Browse the repository at this point in the history
  • Loading branch information
Siobhan committed Sep 19, 2022
1 parent 9fe2474 commit f61ab8a
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions client/blocks/app-banner/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -255,18 +255,20 @@ export class AppBanner extends Component {

function BannerIcon( { icon } ) {
useEffect( () => {
const reducedMotion = window.matchMedia( '(prefers-reduced-motion: reduce)' ).matches;

const animation = lottie.loadAnimation( {
container: document.querySelector( '.app-banner__icon' ),
renderer: 'svg',
loop: false,
autoplay: true,
autoplay: ! reducedMotion,
path: icon,
} );

const reducedMotion = window.matchMedia( '(prefers-reduced-motion: reduce)' ).matches;

if ( reducedMotion ) {
animation.goToAndStop( 145, true );
animation.addEventListener( 'config_ready', () => {
animation.goToAndPlay( animation.totalFrames, true );
} );
}

return () => animation.destroy();
Expand Down

0 comments on commit f61ab8a

Please sign in to comment.