Skip to content
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

start: 'manual' not working for 'scenario' type #148

Closed
sbastias opened this issue Mar 5, 2017 · 16 comments
Closed

start: 'manual' not working for 'scenario' type #148

sbastias opened this issue Mar 5, 2017 · 16 comments

Comments

@sbastias
Copy link

sbastias commented Mar 5, 2017

Thanks for the library!

I've got a cool animation going with scenario, but if i try to change start to 'manual' and then call .play(), the callback is called immediately, and the animation doesn't start.

vivusLogo = new Vivus('logo', {start: 'manual', type: 'scenario', file: 'logo-wordmark3.svg?'+Math.random()})

vivusLogo.play(0.5, function(){ console.log('logo completed') })

The timing directives are explicit in my svg file, and it works with inViewport and autostart.

@maxwellito
Copy link
Owner

Hi there,
Can you please provide me your SVG, I would like to have a look to have a better understanding. Thanks :)

@sbastias
Copy link
Author

sbastias commented Mar 5, 2017 via email

@sbastias
Copy link
Author

sbastias commented Mar 5, 2017 via email

@maxwellito
Copy link
Owner

maxwellito commented Mar 5, 2017

You're welcome! :-)
That was an easy one ;-)

@maxwellito maxwellito reopened this Mar 5, 2017
@sbastias
Copy link
Author

sbastias commented Mar 5, 2017 via email

@maxwellito
Copy link
Owner

Sorry I thought you were saying you were using the wrong file in your code. My bad :-S
I'm looking at it, I'll be back soon

@maxwellito
Copy link
Owner

I didn't realise you don't wait for the SVG to be loaded to start to play it. When the dynamic load is used (via the property file), the callback onReady must be used.

vivusLogo = new Vivus('logo', {
	start: 'manual',
	type: 'scenario',
	file: 'logo-wordmark3.svg?'+Math.random(),
	onReady: function () {
		// Now I'm ready :) Let's play!
		vivusLogo.play(0.5, function(){ console.log('logo completed') })
	}
})

// Do not trigger it here, the SVG is not ready
// vivusLogo.play(0.5, function(){ console.log('logo completed') })

http://maxwellito.github.io/drafts/vivus-issue-148/

@sbastias
Copy link
Author

sbastias commented Mar 5, 2017 via email

@sbastias
Copy link
Author

sbastias commented Mar 5, 2017 via email

@maxwellito
Copy link
Owner

Yup :)
Depends what would be for you the trigger of the animation?

@sbastias
Copy link
Author

sbastias commented Mar 5, 2017

Ok, here's my use case.

On loading my SPA, I call:

window.vivusLogo = new Vivus('logo', {start: 'manual', type: 'scenario', file: 'logo-wordmark3.svg?'+Math.random(), onReady: function(){
        vivusLogo.reset().stop()
      }})

...and then later in my application logic:

window.vivusLogo.play(function(){ console.log('logo completed') })

But when i call .play(), the callback runs immediately and animation doesn't start. (Same problem when i don't include the .reset().stop())

@maxwellito
Copy link
Owner

var autostart = false,
    vivusLogo = new Vivus('logo', {
      start: 'manual',
      type: 'scenario',
      file: 'logo-wordmark3.svg?'+Math.random(),
      onReady: function () {
        // Now I'm ready :) Let's play!
        if (autostart) startAnimation()
      }
    })

function startAnimation () {
  if (vivusLogo.isReady) {
    vivusLogo.play(0.5, function(){ console.log('logo completed') })
  }
  else {
    autostart = true;
  }
}

Then call startAnimation() when you need.

@sbastias
Copy link
Author

sbastias commented Mar 5, 2017

Perfect! It's working.

I'm not sure I understand the logic? When I call startAnimation, autostart is set to TRUE... how does the onReady function get called again? Just out of curiousity.

@maxwellito
Copy link
Owner

Hehe :)
Sorry for not leaving more details, here is the story.

  1. The vivus object is set up. This one start to load the SVG

1st scenario:

  1. The SVG is loaded, then vivus trigger the onReady callback. But because autostart variable is not true.. nothing happens.
  2. [At some point] your code trigger startAnimation(), this one will check if the vivus instance is ready (which is the case) so it starts playing it.

2nd scenario:

  1. Your code trigger startAnimation(), this one will check if the vivus instance is ready (which is NOT the case) so it only switch the autostart variable to true (as a marker).
  2. The SVG is loaded, then vivus trigger the onReady callback. This time, the autostart variable is true, so it trigger startAnimation(). And this time, the vivus instance is ready so it play the animation.

The reason I use the same function (on the onReady and manually) is because it will avoid redefining the setting of the play. It's at only one place.

I hope this explanation helps :-)

@sbastias
Copy link
Author

sbastias commented Mar 5, 2017 via email

@maxwellito
Copy link
Owner

Uhmmm... onReady and play are separate. It's only in our case that we manage to call play in the onReady if we need to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants