Streaming live at 10am (PST)

Parent/Sibling Navigation Structure

I have a navigational structure like in the images below.

What I want is to display a list of all the patterns when clicking through the All UI Patterns menu item. It also needs to be the active menu item (that’s the easy part though). But then, because the Product Slider is conceptually a sibling of All UI Patterns, the parent (All UI Patterns) need to remain active.

Currently I’ve put the patterns in a folder but that doesnt help because I cant use the folder as a destination link.

How would I achieve this?


You can do this with custom code.

Ok, cool! How would I do that?

Write JavaScript code that selects the first menu item and gives it the class of w--current. Place it in every child page.

Sorry for my ignorance, but I don’t know JS. I’m not exactly sure what to Google for, but I found something that seem like a solution to me:

$(document).ready(function() { $("#menu").on("click", function() { $("#menu").removeClass("w--current"); $(this).addClass("w--current"); }); });

Or not?

You just need something like this

var Webflow = Webflow || [];
Webflow.push(function() {
  $('#menu a').first().addClass("w--current");

Perfect! That seems to work. Thanks Sam.

Just to clarify for others in the future, here’s what I did:

I gave an ID to the parent of the menu item links. In Sam’s example above, it’s called #menu, but I called mine #all-ui-patterns. You can call it whatever you want to.

I then copied the script to the head tag of every page I wanted to have an active state.

And the result is this:

Hope that makes sense. :wink:



This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.