samodurow Posted July 8 Share Posted July 8 Hi, I peeked at the realization of the accordion. Thanks a lot to the author. And how to make the first menu item to be open by default? When clicking on another item, the first item should close. Help please. See the Pen zYpQVxj?editors=0010 by PointC (@PointC) on CodePen Link to comment Share on other sites More sharing options...
Solution Rodrigo Posted July 9 Solution Share Posted July 9 Hi, This should be a question for the author actually: https://codepen.io/superbenj/details/RwxmOvQ Craig actually forked that one, most likely to answer a question here in the forums. For what I can see from the code this should do the trick though: let groups = gsap.utils.toArray(".accordion-group"); let menus = gsap.utils.toArray(".accordion-menu"); let menuToggles = groups.map(createAnimation); menus.forEach((menu) => { menu.addEventListener("click", () => toggleMenu(menu)); }); function toggleMenu(clickedMenu) { menuToggles.forEach((toggleFn) => toggleFn(clickedMenu)); } function createAnimation(element) { // ... } toggleMenu(menus[0]); Hopefully this helps. Happy Tweening! 1 Link to comment Share on other sites More sharing options...
samodurow Posted July 9 Author Share Posted July 9 12 hours ago, Rodrigo said: Hi, This should be a question for the author actually: https://codepen.io/superbenj/details/RwxmOvQ Craig actually forked that one, most likely to answer a question here in the forums. For what I can see from the code this should do the trick though: let groups = gsap.utils.toArray(".accordion-group"); let menus = gsap.utils.toArray(".accordion-menu"); let menuToggles = groups.map(createAnimation); menus.forEach((menu) => { menu.addEventListener("click", () => toggleMenu(menu)); }); function toggleMenu(clickedMenu) { menuToggles.forEach((toggleFn) => toggleFn(clickedMenu)); } function createAnimation(element) { // ... } toggleMenu(menus[0]); Hopefully this helps. Happy Tweening! Thank you, that's just what I needed. It's so simple... Need to learn gsap better 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