Menu/navigation bar designed with floating lines and an array of color options

I'm currently working on implementing this specific menu into my Wordpress site.

My main concern is figuring out how to customize the hover effect for each navigation item. Currently, the float line changes to red (

background-color:#800; height:2px;
) when hovered or selected across all items.

What I aim to achieve is as follows:
For Menu 1 - floating line turns green,
Menu 2 - line becomes yellow,
Menu 3 - red, Menu 4 - blue, and so forth.

Any suggestions or guidance on achieving this customization would be greatly appreciated.

Thank you.

Answer №1

If you're looking for a more CSS-centric approach, there is a way to achieve the desired effect with some JavaScript to enhance readability. In this method, it's important for your pages to correctly initialize the float line (`.highlight`) and the navigation border (`#sses1 > ul`).

While the optimal solution would involve a class for each float line, below is a JavaScript-only implementation:

<!-- added individual classes for nav items -->
<div id="sse1">
  <div id="sses1>
    <ul>
      <li><a class="nav-item-1" href="?menu=1&skin=2&p=Javascript-Menus">Javascript Menus</a></li>
      <li><a class="nav-item-2" href="?menu=1&skin=2&p=Horizontal-Menus">Horizontal Menus</a></li>
      <li><a class="nav-item-3" href="?menu=1&skin=2&p=Web-Menus">Web Menus</a></li>
    </ul>
  </div>
</div>

Prior to the page or window loading:

function customHandleMenu() {
    // retrieve nav selector
    var nav = $('#sses1 > ul');

    // retrieve float line selector
    var floatLine = $('.highlight'); // .hightlight must be present at this point

    // obtain colors for the current page
    var defaultBGcolor = floatLine.css('background-color');
    var defaultBorderColor = floatLine.css('border-color');
    var defaultNavBorderColor = nav.css('border-bottom-color');

    // adjust background-color and border-color on mouseenter event

    $('.nav-item-1').on({
        mouseenter: function () {
            setColors({floatColor:'#0f0', borderColor:'#0f0'});
        }
    });

    // Additional mouseenter events for other nav items

    // restore default colors on mouseleave event
    $('#sses1 > ul > li').on({
        mouseleave: function() {
          setColors({floatColor:defaultBGcolor, borderColor:defaultNavBorderColor});
        }
    });

    function setColors(args) {
        if (typeof args.floatColor != "undefined") {
            floatLine.css('background-color', args.floatColor);
        }

        if (typeof args.borderColor != "undefined") {
            floatLine.css('border-color', args.borderColor);
            nav.css('border-bottom-color', args.borderColor);
        }
    }
}

To ensure the selector only operates once `.highlight` exists, consider modifying the end of the original script as follows:

function initMenu() {
    sse1.buildMenu();
    customHandleMenu();
}

if (window.addEventListener) {
    window.addEventListener("load", initMenu, false);
}
else if (window.attachEvent) {
    window.attachEvent("onload", initMenu);
}
else {
    window["onload"] = initMenu;
}

You can view a sample implementation in this jsfiddle link.

P.S.: The event chain has been slightly adjusted to accommodate jsfiddle.

Answer №2

What you're requesting is quite complex. The developer of the plugin is essentially animating the width and position of an li element with the class "li.highlight" based on mouse hover. Changing the color of this element can be done by modifying the CSS definition. To make it yellow, simply add the following CSS code below the menu's stylesheet:

#sses1 li.highlight {
    background-color: yellow;
    top: 36px;
    height: 2px;
    border-bottom: solid 1px yellow;
    z-index: 1;
    position: absolute;
    overflow: hidden;
}

This may not be a complete solution, but if you're up for it, you could customize the JavaScript to add a new class based on the parent li element of the .highlight element.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Create a single button that controls checkboxes with the help of HTML, CSS, SCSS, and Bootstrap 4

Is there a way to use only HTML, CSS, SCSS, and Bootstrap 4 to make all checkboxes default to the "on" condition when a button is clicked? Typically, this functionality would be achieved with JavaScript, but due to constraints, I am exploring alternative ...

What is the best way to tally the number of occurrences a value is true within an hour or day using React?

I am developing an alarm application and I want to track the number of times the alarm has been triggered within an hour and a day. Utilizing redux toolkit, I manage the state of the alarm (on/off) and have a reducer called countAlarm to increase the count ...

row-1 css classes on the top in a project built with Blazor

I'm currently working on customizing the standard layout provided in Blazor projects like WASM or server, but I'm a bit perplexed by the top-row px-4 css classes. Within the HTML code that appears to define the top row/header section is this sni ...

When the file is active on a local machine, the bot commands run smoothly. However, these commands do not execute on a remote

Lately, while working on coding a discord bot using discord.js, I came across an issue. Whenever I run my bot on my local machine, all the commands work perfectly fine. However, after committing and pushing the code to GitHub, and then allowing buddy.works ...

Can you explain the process that takes place when require("http").Server() is called with an Express application passed in as a parameter?

As I was exploring the Socket.io Chat Demo found at this link: http://socket.io/get-started/chat/, I came across their require statements which left me feeling confused. var app = require('express')(); var http = require('http').Server ...

CSS - stacking containers vertically with scrollbars

I am in need of a vertical stack of blocks, which may include scrolls, contained within a fixed-sized container without scrolls. The number of visible blocks is dynamically managed by JavaScript code. Some blocks can be hidden or shown, and when a block is ...

Issues with fetching data from a Drupal module using an Ajax call

I have created a custom module in Drupal where the .js file is supposed to make an ajax call to a .module file. However, I am facing issues as the ajax call is not functioning properly. Can someone please assist me with this? Below is my .js file: // Jqu ...

Unsupported file format for Three.js FBX Binary model

I am currently working with three.js in a mobile application that is built using JavaScript. I am trying to incorporate a 3D model using an .fbx file, but I am facing issues with the binary format not being supported by FBXLoader. As someone who doesn&apos ...

Different results are being obtained when destructuring props in a component

Just diving into the world of React and trying to grasp destructuring. I've been doing some reading on it, but I'm currently stuck. When I try to destructure like this function MList({action}) { // const data = [action];}, I only get 'camera ...

Dealing with a Promise and converting it into an array: a step-by-step

I am encountering difficulties progressing with my Promise returned from the getPostedPlaces() function. After executing getAll(), an Array is displayed as shown below. Although the array appears to be correct, I am unsure how to make the getAll() function ...

Adjust camera to align with the loaded object in Three.js

I've been struggling to center the camera around the model loaded through the stl loader. I've tried adjusting variables and setting different positions for the mesh and camera, but the camera still isn't centered on the design! Here's ...

What could be causing the visibility issue with my navigation items in the bootstrap navigation bar?

Currently, I am experiencing a puzzling issue with the navigation bar on my live website. The navigation items seem to flicker for a brief moment and then disappear entirely. This unexpected behavior is certainly causing me some concern. I crafted the us ...

Angularjs - Transferring the $scope object to a controller

While taking Angular's complimentary online course, I came across the following code snippet: app.controller('GalleryController', function(){ this.current = 0; this.setCurrent = function(imageNumber){ this.current = imageNumber || 0 ...

Exploring characteristics using DocumentTraversal

My goal is to list out the attributes of elements using DocumentTraversal specifically for IE11. While I have been successful in enumerating element attributes, I am facing an issue when trying to do the same with attributes. The enumeration stops at the f ...

Is it possible to extract a div from a third-party domain and showcase it on my website?

Trying to integrate content from my Veetle.com channel onto my personal website has proven to be quite the challenge. Initially, I attempted to modify an iframe with CSS to display only the schedule information, but encountered limitations due to using 3rd ...

Interactive pop-up windows in Bootstrap

I encountered an issue with bootstrap modal forms where the form displays correctly after clicking on the button, but the area in which the form is displayed gets blocked! It's difficult to explain, but you can see the problem by visiting this link. ...

How can I transfer the data from a file to upload it in Angular 9 without manually typing it out?

In my Angular application, I have a functionality where users can upload two files for processing on the server. However, I am looking to add a feature that allows users to simply copy and paste the contents of the files into two textboxes instead of going ...

"Revamp the appearance of the div element upon clicking elsewhere on the

function replace( hide, show ) { document.getElementById(hide).style.display="none"; document.getElementById(show).style.display="flex"; } @import url('https://fonts.googleapis.com/css2?family=Allerta+Stenci ...

dividing values for future angular use

Within my code, I have the following snippet: color: {{item.color}} This setup functions well when dealing with single items. However, there are instances where I encounter a value such as: white|black Is there a way to separate these values into indiv ...

Receiving an item in place of a true/false indicator

I wrote an asynchronous function that validates the permission status on a device. Here is the function: checkPermission = async () => { const allowed = await requestNotifications(['alert', 'sound']).then((res) => { if ...