Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
Sameh_07

Problem with making a timeline that dynamically animates a different element every repetition, with Vue

Go to solution Solved by GreenSock,

Recommended Posts

I'm trying to make a simple slider that animates-in then out one slide after the other according to the currentStep variable, which gets incremented by 1 at the end of every slide, but nonetheless , I end up getting the same slide over and over again and can't figure out why...

 

See the Pen mdmPwMN by samehhashy (@samehhashy) on CodePen

Link to comment
Share on other sites

You're only adding slide 1 to the timeline.

The component mounts - you add the animation for slide one, then on timeline complete you increment the item number but you don't actually add anything else to the timeline.

It's just looping the one slide you've told it to animate.

Link to comment
Share on other sites

2 minutes ago, Cassie said:

You're only adding slide 1 to the timeline.

The component mounts - you add the animation for slide one, then on timeline complete you increment the item number but you don't actually add anything else to the timeline.

It's just looping the one slide you've told it to animate.

What I wanted to do is to repeat the same timeline but for the new slide, hoping that by then the ref would be updated.

Is there something wrong with this logic?

  • Like 1
Link to comment
Share on other sites

That's not how timeline's work - a repeat isn't like a code loop. It's an animation loop.

It's repeating the animation using the element it was instantiated with (slide 1) So it'll just repeat slide 1 forever.

 

If you want to loop through and add the other slides to that timeline you'll need to actually make an if/while/foreach loop

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

  • Solution

Here's an example of what @Cassie was describing: 

See the Pen oNWxVgd by GreenSock (@GreenSock) on CodePen

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

Vue tip. Use a single ref name with v-for.

<div :key="i" ref="items" class="item"></div>

 

It will automatically add them to an array.

this.items.forEach((cur, i) => {
  let item = this.$refs.items[i];
  ...
});

 

See the Pen MWmyxbJ by GreenSock (@GreenSock) on CodePen

 

  • Like 2
  • Thanks 1
Link to comment
Share on other sites

Thank you all! that's been very helpful.
I now understand what exactly repeat does.

  • Like 2
Link to comment
Share on other sites

And I know know more about Vue refs! *high five* 🙌

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×