Jump to content
Search Community

Infinite Carousel – Wrapping Issue

oscarsidebo test
Moderator Tag

Go to solution Solved by GreenSock,

Recommended Posts

  • Solution

Nah, it's a logic issue in your code. GSAP is doing exactly what you're asking, but each of those elements is a different distance from the x value where it should wrap so you need to do individual calculations for each one. I assume you meant to do something more like this: 

 

const elements = gsap.utils.toArray(ref.current.querySelectorAll(".flexItem"));
const containerBounds = ref.current.getBoundingClientRect();
const widest = Math.max(...elements.map(el => el.offsetWidth));

elements.forEach(el => {
  const bounds = el.getBoundingClientRect();
  gsap.to(el, {
    duration: 10,
    ease: "none",
    repeat: -1,
    x: -containerBounds.width - widest,
    modifiers: {
      x: gsap.utils.unitize(gsap.utils.wrap(containerBounds.left - widest - bounds.left, containerBounds.right - bounds.left), "px")
    }
  });
});

Also, you don't need to import ModifiersPlugin - that's baked into the core. :)

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