jollygreen Posted January 16, 2023 Share Posted January 16, 2023 I'm assuming the ScrollTo plugin is free to use. Could you please advise why the scroll to code on this pen doesn't animate? See the Pen jOpGOwO by jollygreen10 (@jollygreen10) on CodePen Link to comment Share on other sites More sharing options...
Rodrigo Posted January 16, 2023 Share Posted January 16, 2023 Hi, That's because the default action takes precedence and sets the scroll position to the hash. You have prevent that and it should work: document.querySelectorAll("#menu a").forEach((item, index) => { item.addEventListener("click", (event) => { // Prevent the default action event.preventDefault(); let target = event.target; let hash = target.hash; console.log(hash); gsap.to(window, { duration: 1, scrollTo: hash, ease: "Power1.easeInOut" }); }); }); Let us know if you have more questions. Happy Tweening! 1 Link to comment Share on other sites More sharing options...
jollygreen Posted January 16, 2023 Author Share Posted January 16, 2023 Thank you very much, Rodrigo. It's working. Link to comment Share on other sites More sharing options...
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