Jump to content
Search Community

Nested dropdowns

Ian Robinson test
Moderator Tag

Go to solution Solved by Ian Robinson,

Recommended Posts

Hey Greensockers! Found this very helpful pen and wanted to expand upon it by nesting drop-downs within drop-downs. I had tried by duplicating the code and giving the nested divs different class names but that didn't seem to work at all (plus it felt like a very heavy-handed solution).  Thanks in advance!

See the Pen vYMVgwm by ilrobinson (@ilrobinson) on CodePen

Link to comment
Share on other sites

This is mostly a structure question and hasn't really to do with GSAP. I would abstract out what are toggle and what are expended elements and then expand all the elements that are connected to the toggle. As you see in your example you don't want to expand elements that have them self content that also should expand, so the HTML structure (and CSS) is really important in this case. 

 

I've given each element data-toggle and data-expand with their respective key (eg the name on the link). Right now it doesn't close, personally I don't like it when toggles close them selfs and I think it is bad UX. What If I want to compare content one and three?

 

You could could add a data-close and find all the elements that should close if some data-toggle is clicked, but agin this isn't really a GSAP question, but again more JS logic and is beyond the scope of this forum. Still hope it helps and happy tweening! 

 

See the Pen BaEqJOM?editors=1101 by mvaneijgen (@mvaneijgen) on CodePen

  • Like 3
Link to comment
Share on other sites

Thanks, Mvaneligen!  It's close, but due to the amount of information (there will be dozens of sub-menus within each menu item) and how it's presented I want it to function like my second version where main menus collapse when others are opened, and the same with the sub-menus as otherwise it's just a long list of drop-downs that the user has to go back and keep closing.

Link to comment
Share on other sites

  • Solution

I complain about using pre-fab code as it's generally too much work to reverse-engineer and tweak but that's what I was doing right here. Came up with a straight CSS/jQuery solution in like 30 minutes versus the hours I was working on the previous code. Plus I can expand with GSAP if need be but works great just like this if anyone else is looking for the same thing (and can add in GSAP)

*I'll add to this CodePen if I end up infusing some GSAP though to keep it relevant to the community

See the Pen ExJOvga by ilrobinson (@ilrobinson) on CodePen

  • Like 1
Link to comment
Share on other sites

Hey Ian,

 

Great to hear that you were able to solve this 🥳

 

Finally thanks for sharing  your solution with the community, I'm sure many users will benefit from your  generosity 💚

 

Happy Tweening!

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