Jump to content
Search Community

move container from left to right in a loop

wzrdKB test
Moderator Tag

Go to solution Solved by GreenSock,

Recommended Posts

I guess that this is a fairly easy task, but I am trying since 2 days to get this to work...
Basically I just want to move a container from right to left in a loop. The container contains blog-tags and since there are many tags, some of them are overflowing. That's why I want to animate them. 

The animation from right to left works just fine. Here is the code:
 

$kb_tags = $('.kb-tags-group');
        
    let tween = gsap.to(".kb-tags-group", {
            duration: 8, 
            x: () => $kb_tags.offsetWidth, // animate by the px width of the nav
            xPercent: -150, // offset by the width of the box
            ease: "none", 
            repeat: -1,
          });

    });

2023_04_24_15_20_48_Kienbaum_Blog_Expertenwissen_zu_HR_und_Organisationsthemen.png.6f2ae0f2e075f09df3b6bc4f32868dbf.png
But the Problem is, that after the animation ends, the animation stops/starts abruptly from x again.
I want it to be a seamless loop, without white-space. So the tags should move to left, and then appear from the right side again.

What would be the best way to do this?
Thank you very much in advance!!!!

Link to comment
Share on other sites

7 hours ago, GreenSock said:

Welcome, @wzrdKB

 

Having things wrap around the other side like that is actually pretty tricky to pull off due to logic stuff. We whipped together a helper function in the docs that should make it a whole lot easier: https://greensock.com/docs/v3/HelperFunctions#loop

 

Good luck!

Thank you so much!!! I finally did get it to work.... Since I want to learn:

Could it be, that the helper functions does not work when using hyperlinks as elements?
I had to wrap each <a> in a seperate <div> for it to work. Or may it be related to another conflict with my stylesheets, and that's why it did not want to work?

Link to comment
Share on other sites

  • Solution
2 hours ago, wzrdKB said:

Could it be, that the helper functions does not work when using hyperlinks as elements?
I had to wrap each <a> in a seperate <div> for it to work. Or may it be related to another conflict with my stylesheets, and that's why it did not want to work?

It's probably just because browsers won't apply transforms to display: inline elements (that is unrelated to GSAP). You could set those to display: inline-block instead. 

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