question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support `goToAndStop`?

See original GitHub issue

Hi there,

I’m interested in being able to set the exact frame of the animation, so that I can sync the animation as the user scrolls down the page.

For now, I’ve created a subclass of Lottie that takes a percentage parameter and then uses it to set the frame:

export default class LottieWithAnimationControl extends Lottie {
  static propTypes = {
    ...Lottie.propTypes,
    percentage: PropTypes.number,
  }

  anim: any
  props: Props

  componentDidUpdate(prevProps: Props, prevState: any, prevContext: any) {
    if (super.componentDidUpdate) {
      super.componentDidUpdate(prevProps, prevState, prevContext)
    }

    if (this.props.percentage !== prevProps.percentage && this.anim.totalFrames) {
      const frame = Math.round(this.anim.totalFrames * this.props.percentage)
      this.anim.goToAndStop(frame, true)
    }
  }
}

However, what do you think of supporting this natively in the component?

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:15
  • Comments:6

github_iconTop GitHub Comments

1reaction
gigameshcommented, Jul 20, 2018

@jessepinho Thanks for this! I’ve been looking for something like it for days. 😃

Is there any chance you could walk through how it works? I’m pretty new to JS and React, so I’d really appreciate the lesson. I roughly understand the last section calculating which frame to be on using a percentage received from the parent component, but I’m pretty confused about everything before that (aside from propTypes). These lines are particularly mysterious to me:

  anim: any
  props: Props

prevState: any, prevContext: any

0reactions
peterlovelandcommented, May 15, 2020

@gigamesh @wahlforss I’m hacking something together needing this basic functionality, using the code from @jessepinho I got this to work using the following, I’ve simplified down the use case a bit but the following is the ‘barebones’: (Basically I just removed all the bits that were confusing you and that seemed to do the trick)

import React from 'react';
import Lottie from 'react-lottie';

export class LottieWithAnimationControl extends Lottie {
  componentDidUpdate() {
    const frame = Math.round(this.anim.totalFrames * this.props.percentage)    
    this.anim.goToAndStop(frame, true)
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

MovieClip.gotoAndStop( ) Method - ActionScript - O'Reilly
Name MovieClip.gotoAndStop( ) Method — jump to a given frame, and stop the playhead Availability Method form introduced in Flash 5 (global form...
Read more >
expression "gotoandstop" ? HELP ! - Adobe Support Community
Hello, I'm looking to write an expression that would move the playhead of a composition into a named layer.
Read more >
currentFrame and goToAndStop method issue + playTo method
Hi ! Awesome library ! I want to make an interactive animated button with lottie and I like to know if it's possible...
Read more >
How to use the lottie-web.goToAndStop function in ... - Snyk
To help you get started, we've selected a few lottie-web.goToAndStop examples, based on popular ways it is used in public projects.
Read more >
LottieAnimation QML Type | Qt Lottie Animation 6.2.7
Currently, only subset of the full Bodymovin specification is supported. ... starts go here gotoAndPlay(startFrame); } } onFinished: { console.log("Finished ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found