Jump to content
Search Community

Recommended Posts

Posted

Hello, everyone! I made this horizontal scroll using gsap. But switching the active class for the link does not work for me and when I click on the link again, the active section scrolls to the left.

See the Pen VwoVgaG by brilyuk (@brilyuk) on CodePen.

Posted

I have solved the problem with repeated clicking on the link and incorrect scrolling of the section.

document.querySelectorAll(".header__menu-aside a").forEach((element) => {
 element.addEventListener("click", function (e) {
  e.preventDefault();
  const id = this.getAttribute("href").split("#")[1];
  const targetElement = document.getElementById(id);
   
  if (!targetElement) return;
  const scrollToHere = targetElement.offsetLeft;

  gsap.to(scrollContainer, {
   x: "-" + scrollToHere,
   duration: 2,
   ease: "power2.inOut"
  });
 });
});

 

Posted
11 minutes ago, brilyuk said:

I have solved the problem with repeated clicking on the link and incorrect scrolling of the section.

document.querySelectorAll(".header__menu-aside a").forEach((element) => {
 element.addEventListener("click", function (e) {
  e.preventDefault();
  const id = this.getAttribute("href").split("#")[1];
  const targetElement = document.getElementById(id);
   
  if (!targetElement) return;
  const scrollToHere = targetElement.offsetLeft;

  gsap.to(scrollContainer, {
   x: "-" + scrollToHere,
   duration: 2,
   ease: "power2.inOut"
  });
 });
});

 

Sorry, but this does not solve the problem(((

Posted
50 minutes ago, brilyuk said:

Hello, everyone! I made this horizontal scroll using gsap. But switching the active class for the link does not work for me and when I click on the link again, the active section scrolls to the left.

Updated the script.js It seems to work now

  • Like 1

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