Jump to content
Search Community

ScrollToPlugin for RTL Tab Navigation

Sovai test
Moderator Tag

Go to solution Solved by Rodrigo,

Recommended Posts

Hello GSAP Community,

 

I am working on a Vue 3 project and facing an issue with implementing RTL support for a tab navigation system where the active tab should center on click. My current implementation with GSAP's ScrollToPlugin works fine for LTR, but fails in RTL mode.
Tabs are dynamically generated and centered using scrollTo from GSAP when clicked.


Current Issue:
Adding dir="rtl" to my scroll container breaks the centered alignment of the tabs. The function calculating the scroll position seems to not accommodate RTL.

 

I tried to not use RTL direction and reverse sort the data + unshift when add new items but its a lot of works and introduce more bugs so if i can get help to fix RTL instead it will be the best choice.

 

Thanks for your help

See the Pen bGyGdpb by sovai (@sovai) on CodePen

Link to comment
Share on other sites

Also any suggest for a better way to make content scroll to center without hard code to add blank items before and after?

Link to comment
Share on other sites

  • Sovai changed the title to ScrollToPlugin for RTL Tab Navigation
  • Solution

Hi and sorry for the delay answer, this one slipped through the cracks 🙏

 

The issue here is mostly about the calculations and the use of absolute values. I made a few changes in your setup, removed some elements you were using to center the list and used relative values to translate the element that contains the tabs instead of using scrolling and it seems to work the way you intend:

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

 

Hopefully this helps.

Happy Tweening!

Link to comment
Share on other sites

Hi @Rodrigo, that's awesome! I just need to add arrow width for calculation to make the arrow center. 

 

const calculateCenteredScroll = (element) => {
  try {
    const elementRect = element.getBoundingClientRect();
    const containerRect = scrollContainer.value.getBoundingClientRect();
    const arrowWidth = 12;
    return (
      (containerRect.width - elementRect.width + arrowWidth) / 2 - elementRect.x
    );
  } catch (error) {
    console.log("error: ", error);
  }
};

 

Cheer!

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