Jump to content
Search Community

motionpath target multiple objects and gap between on one path

morag test
Moderator Tag

Go to solution Solved by mvaneijgen,

Recommended Posts

hi there,

im using motionpath.

i have an array of multiple objects. and they all need to loop on the same path.

my problem is the space between the items. i did a delay but when you get to the section not all of them started the loop yet..

 

how can i create a space between them on the path?

thank you

here is my code:

//values elips
    if ($(".elips").length > 0) {
        const elips = document.querySelector('.elips')
        const elipsMobile = document.querySelector('.elips-mobile')
        const hpValues = gsap.utils.toArray('.hp-value');
        hpValues.forEach((hpValue, i) => {
            gsap.to(hpValue, {
                motionPath: {
                    path: isDesktop ? elips : elipsMobile,
                    align: isDesktop ? elips : elipsMobile,
                    alignOrigin: [0.5, 0.5],
                    //autoRotate: -90,
                    immediateRender: true,
                },
                opacity: 1,
                repeat: -1,
                duration: 20,
                ease: "none",
                delay: i * 2,
            })
        })
    }

 

Link to comment
Share on other sites

Have you tried just using the start/end properties to offset things on the path?

 

If that doesn't help, please make sure you provide a minimal demo (like a CodePen) so we can see what's going on in context. 

 

Please don't include your whole project. Just some colored <div> elements and the GSAP code is best (avoid frameworks if possible). See if you can recreate the issue with as few dependancies as possible. If not, incrementally add code bit by bit until it breaks. Usually people solve their own issues during this process! If not, then at least we have a reduced test case which greatly increases your chances of getting a relevant answer.

 

Here's a starter CodePen that loads all the plugins. Just click "fork" at the bottom right and make your minimal demo

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

 

If you're using something like React/Next/Vue/Nuxt or some other framework, you may find StackBlitz easier to use. We have a series of collections with different templates for you to get started on these different frameworks: React/Next/Vue/Nuxt.

 

Once we see an isolated demo, we'll do our best to jump in and help with your GSAP-specific questions. 

Link to comment
Share on other sites

  • Solution

@morag first of welcome to the forum!

 

What I would do is distribute the items on the path based on their start and end position, if you want more info on these properties check the MotionPathPlugin docs

 

Just to create a quick example I've removed 2 of your elements, because with 5 items the offset was easy to calculate (but you can easily do some calculations to get it with any number of elements). The motion path end and start values go from 0 to 1 meaning with 5 elements each takes up 0.2 (0.2 * 5 = 1) and then for the end value I just do the same, but add 1 to it, because you can create larger numbers then 1 and it will just make that the items go round the path again. 

 

See the Pen poOrYeW?editors=0011 by mvaneijgen (@mvaneijgen) on CodePen

  • Like 2
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.
×
×
  • Create New...