Jump to content
Search Community

How to make the first accordion menu item to be open by default?

samodurow test
Moderator Tag

Go to solution Solved by Rodrigo,

Recommended Posts

  • Solution

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!

  • Like 1
Link to comment
Share on other sites

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

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