brilyuk Posted November 9, 2024 Posted November 9, 2024 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.
brilyuk Posted November 9, 2024 Author Posted November 9, 2024 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" }); }); });
brilyuk Posted November 9, 2024 Author Posted November 9, 2024 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(((
brilyuk Posted November 9, 2024 Author Posted November 9, 2024 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 1
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now