Sameh_07 Posted July 7, 2021 Share Posted July 7, 2021 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 More sharing options...
Cassie Posted July 7, 2021 Share Posted July 7, 2021 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 More sharing options...
Sameh_07 Posted July 7, 2021 Author Share Posted July 7, 2021 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? 1 Link to comment Share on other sites More sharing options...
Cassie Posted July 7, 2021 Share Posted July 7, 2021 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 1 1 Link to comment Share on other sites More sharing options...
Solution GreenSock Posted July 7, 2021 Solution Share Posted July 7, 2021 Here's an example of what @Cassie was describing: See the Pen oNWxVgd by GreenSock (@GreenSock) on CodePen 1 1 Link to comment Share on other sites More sharing options...
OSUblake Posted July 7, 2021 Share Posted July 7, 2021 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 2 1 Link to comment Share on other sites More sharing options...
Sameh_07 Posted July 8, 2021 Author Share Posted July 8, 2021 Thank you all! that's been very helpful. I now understand what exactly repeat does. 2 Link to comment Share on other sites More sharing options...
Cassie Posted July 8, 2021 Share Posted July 8, 2021 And I know know more about Vue refs! *high five* 🙌 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now