Jump to content
GreenSock

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

Multiple independent timelines in Nuxt

Recommended Posts

Sorry for the noob question here, but I can't seem find it anywhere, so here goes.

 

My nuxt.js index page has several 'panel' components. Each one is full page, and are animated like on this codepen.

 

 

Because I'm working with Nuxt, on the main page (responsible for animating the 'panels') I'm using something like:
 

<template>
  <div>
    <panel :content="content_a" />
    <panel :content="content_b" />
    <panel :content="content_c" />
  </div>
</template>


<script>
import { gsap, ScrollTrigger } from 'gsap/all'
import panel from '[path/to/component]'

export default {
  components: {
    panel
  },
  
  data() {
    return {
      tl = gsap.timeline()
    }
  },
  
  mounted() {
    gsap.registerPlugin(ScrollTrigger)

    [... animations defined here ]
  },
    
  methods: {
    playAnim() {
      this.tl.play(0)
    }
  }
}

</script>

 

However, inside each <panel>, I also want to have independent animations. 

If inside a <panel> component I have again

 

<script>
import {gsap, ScrollTrigger} from 'gsap/all
   
export default {
  data() {
    panelTimeline: gsap.timeline()
  },
    
  mounted() {
    gsap.registerPlugin(ScrollTrigger)
    
    [... animations defined here]
  },
  
  methods: {
    playAnim() {
      this.panelTimeline.play(0)
    }
  }
}
</script>

 

is the panelTimeline refering to the same timeline as the parent?

 

I seem to have some interference somewhere in my project and I'm wondering if the parent component ends up sharing the same timeline as the children.

 

I'm using ScrollTrigger on the index (which is the parent of all the panel components), and I've read on the Docs that it uses one single timeline. 

If so, what should be the best way to make sure to have independent timelines?

 

Big thank you in advance. 

 

PS: On gsap v.2, we would do tl: new Timeline()  and that would work (and there was no ScrollTrigger )

 

See the Pen XWXdypQ by urbgimtam (@urbgimtam) on CodePen

Link to comment
Share on other sites

38 minutes ago, BMateus said:

is the panelTimeline refering to the same timeline as the parent?

 

No that's not possible. Do the animations inside your panel use ScrollTrigger? If so, it would probably be better to let the parent handle them.

 

And you don't need to put the timeline on the data object. That's for reactive properties. 

mounted() {
  this.panelTimeline = gsap.timeline()
}

 

  • Like 2
Link to comment
Share on other sites

Hey BMateus. 

 

46 minutes ago, BMateus said:

I seem to have some interference somewhere in my project and I'm wondering if the parent component ends up sharing the same timeline as the children.

I'm guessing you have conflicting animations somewhere.

 

46 minutes ago, BMateus said:

On gsap v.2, we would do tl: new Timeline()  and that would work (and there was no ScrollTrigger )

This is equivalent to tl: gsap.timeline() in GSAP 3.

 

I think you should try setting up a minimal demo of your issue using something like CodeSandbox and share that with us if you're wanting more help:

 

  • Like 1
Link to comment
Share on other sites

Thank you so much for both your answers.

 

@OSUblake, so there is no way to isolate ScrollTrigger animations?

 

As each <panel> is an independent component, it will be hard to control them from the outside. The hard coupling is something I'm trying to avoid, as the components will be reused in other pages.

 

@ZachSaucier, thank you too. My project is getting large. If I can't find what is getting in conflict I'll create a sandbox (codepen won't do for Nuxt) and post it here. Thank you again for your assistance.

Link to comment
Share on other sites

8 minutes ago, BMateus said:

If I can't find what is getting in conflict I'll create a sandbox (codepen won't do for Nuxt) and post it here

Please post a minimal version with everything irrelevant cut out if you do that :) 

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.
×