Jump to content

Making top menu bar more dynamic - highlighting when hovering, underline when clicked

Recommended Posts

Site URL: http://www.mghstudentwellness.org

We are trying to make the top menu bar of our website a bit more dynamic, by having different options highlight when you hover over them, and the top level category (e.g., Resources) remain underlined when anything within that menu is clicked, to help with navigation/not losing one's place. Currently this happens only for the "What we do" item.

I have very basic Square Space editing skills.

Can anyone help? Thank you!

Link to comment
  • Replies 1
  • Views 441
  • Created
  • Last Reply
11 hours ago, MGHCCCSEW said:

Site URL: http://www.mghstudentwellness.org

We are trying to make the top menu bar of our website a bit more dynamic, by having different options highlight when you hover over them, and the top level category (e.g., Resources) remain underlined when anything within that menu is clicked, to help with navigation/not losing one's place. Currently this happens only for the "What we do" item.

I have very basic Square Space editing skills.

Can anyone help? Thank you!

I saw you use jQuery and some other js code snippet to replace the folder url, kindly replace all of them with this 

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
	var folder_link = [
        {
            href: "/what-we-do",
            target: "/our-services-1"
        },
        {
            href: "/who-we-are",
            target: "/about-us"
        },
        {
            href: "/resources-2",
            target: "/resources"
        }
    ]
    $(document).ready(function() {
        $(document).on('click', '.header-nav-folder-title', function(e) {
            var folder_href = $(this).attr("href");
            var folder_item = folder_link.filter(function(f) { return f.href == folder_href; });

            if ( folder_item[0] ) {
                window.location = folder_item[0].target;
            }
            e.preventDefault();
            return false;
        });

        var current_path = window.location.pathname;
        var matched_folder_item = folder_link.filter(function(f) { 
            return current_path == f.target;
        });

        if ( matched_folder_item[0] ) {
            $('.header-nav-folder-title[href="'+matched_folder_item[0].href+'"]').closest("div").addClass("header-nav-item--active");
        }
    });
</script>

image.png.d5a7b9290a8a6add7d9e0cc44d8fa18e.png

BeyondSpace - Squarespace Website Developer

🖼️ Lightbox Studio (Enable Pinch/Zoom on lightbox)
🗓️ Delivery Date Picker (Squarespace Date picker form field)
💫 Gallery block 7.1 workaround
🥳 Sparkplugin Customisations Browsers (Browse +100 Spark plugin customisations)
🥳 Elfsight Template Browsers (Browse +1000 Elfsight widget Templates)

If you find my answer useful, let's leave a like or upvote so others with the same issue can find their solution. Thank you!

 

Link to comment

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.