Using JQuery to visually enhance the menu selection by displaying an image and altering the background color upon hovering

Hello fellow JQuery/Javascript beginners! I recently put together a menu and wanted to add some interactive elements. Specifically, I want the background color to change when a user hovers over an item (simple enough with CSS), but I also want to include an arrow that appears when an item is selected. This arrow should remain visible until another item on the menu is chosen, similar to what Zappos has achieved with their mini floating menu next to the shoes: .

I've already searched through numerous Stackoverflow posts on highlighting selected menu items, but none quite hit the mark like Zappos' implementation.

Any assistance or guidance would be immensely appreciated!

anaanzi

Answer №1

Take a look at my work on JSFiddle here.

If you want to achieve a similar effect on Zappos, use the following code:

$(document).ready(function() {

    $('ul li').hover(
        function() {
        if ( !$('div').hasClass('blue') ) {
            $(this).addClass('gray');
        }
        },
       function() {
           $(this).removeClass('gray');
       }
    );

    $('ul li').click( function() {
        $('ul li').removeClass('blue');
        $(this).addClass('blue');
    });
});

Edit: To add an arrow effect, include a background with an arrow in the CSS class. This can be triggered on hover (gray class) or on click (blue class).

Answer №2

To create a hover effect, you can utilize CSS. If your navigation is structured as an unordered list with the class "nav", your code might resemble the following:

.nav li a:hover {
  background: #95ACC3;
}

For a click effect, jQuery can be used to add a class to the clicked list item. In the example below, the code removes the 'active' class from all list items and then adds it to the clicked item:

$('.nav li').click(function(){
  $('.nav li').removeClass('active');
  $(this).addClass('active');
});

You can view a working example in this jsfiddle link: http://jsfiddle.net/8CMxG/

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

Mask the "null" data in JSON

I'm currently working with a JSON file and trying to display it in a bootstrap table. Check out the code snippet I've been using: $(document).ready(function(){ $.getJSON(url, function(data){ content = '<h1><p class="p1 ...

Implementing CSS in Laravel 8

After placing my CSS file in the public/css folder, I included it in the head section with the following code. <link href="{{ url('/css/app.css') }}" rel="stylesheet"> Unfortunately, the CSS styles are not being applied ...

Why does the content not appear again when switching between tabs?

Hello! I'm facing an issue with toggling between two sets of content on my page. Initially, the correct content shows up, but when I switch tabs, the new content doesn't appear. Furthermore, if I click back to the first tab, that content disappea ...

What is the most effective method for filtering a table using both column-specific and global filters?

Looking for the most efficient way to filter a large chunk of JSON data client-side using a table? Each header has an input filter where users can enter a string to filter that specific property. There is also a global filter for free text search. If you ...

Fetching data using Axios from a specified URL

I am currently facing an issue with the npm package axios while attempting to execute a get request to a specific URL. The problem arises as I consistently receive an error code 503. Here is the snippet of code in question: let data, response; response = ...

Having trouble with `request.auth.session.set(user_info)` in HapiJS?

I've encountered an issue with my strategy that is defined on a server.register(). Although I followed a tutorial, the code seems to be copied verbatim from it and now it's not functioning as expected. server.auth.strategy('standard&apo ...

Attempting to implement the tagify plug-in in order to automatically fill a text field with dynamic labels

I have a code snippet that acts as an event listener for checkboxes inside a dialog box. It allows me to populate or de-populate a text field with values from the checkboxes by checking or unchecking them individually. // Event listener which selects indi ...

Obtain the text content in cases where the DOM is missing both the title and value fields

I am trying to extract the value from a text-box using selenium, but the text-box is marked as readonly and aria-live is set to off. Here is the DOM structure: <input autocomplete="off" class="abc" type="text" role="t ...

Low-quality CSS Gradient Design

Hey everyone, Feel free to take a look at my preloader on this link: (Hit ESC as soon as the page loads to pause the website and focus on the loader) Upon closer inspection, you'll notice that there is an issue with the quality of the background l ...

Other options besides re-flowing and repainting

After doing some research on various platforms like Stack Overflow, I've come across information stating that re-paints and re-flows can be quite taxing on a browser's resources. I am interested in learning about alternative CSS/JS techniques to ...

Here's a guide on how to retrieve the element type or tag type in Selenium using C#

Let's say we have a tag like this: <a class = "fp-anchor fp-forgot-password pull-right" href = "/Account/ForgotPassword">Forgot Password?</a> == $0 In order to determine the type of element, we need to identify if it is a hyperlink. For ...

Combining two Angular expressions

I have two values to work with: {{columns.field}} and {{resultado.!!!}}. The challenge is that I need to include the value of {{columns.field}} inside the !!!, but I'm struggling to figure out how. I have to structure it this way because I am unsure o ...

Converting Excel VBA code to Javascript for use in Google Sheets: A step-by-step guide

Hello everyone, I am looking to convert a VBA code that I wrote into javascript and integrate it into Google Sheets. Does anyone have any suggestions on how I can accomplish this task? The VBA code in question is as follows: Sub Influencers_automacao() ...

The tooltip is being truncated

https://i.sstatic.net/o41Qz.png Struggling with a tooltip that keeps getting cut off? I've tried everything and still can't get it right. <th class="fd-table--header-cell" scope="col"> <p class=&q ...

Simple steps to change JSON Object to JavaScript array

Referring to this question and this other one, I am seeking advice on how to handle a JSON object structure different from the examples provided: This is my JSON Object: var myData = { "04c85ccab52880": { "name": "name1", "firstname": ...

Tips for resolving the React Hook Type Error issue

Error Image const isLoggedIn = true; const handleChangeEvent = () => {}; const [displayPassword, setDisplayPassword] = useState(false); const handleTogglePassword = () => setDisplayPassword((prevDisplayPassword) => !prevDi ...

Using AJAX to showcase data from a table in a database using the <select> tag but with an unfinished submit process

I am encountering an issue with my code. When I submit the value in getinv.php, it only returns a partial value. For example, when I click '2016-08-27', it only retrieves '2016'... My question is, how can I ensure that the exact value ...

Struggling to update the text within a div using HTML5 data attributes

Today, I successfully integrated a feature that allows users to translate web content with a simple button click, eliminating the need for reloading the entire page. I achieved this using html data-* attributes, specifically utilizing a custom data attribu ...

Ways to retrieve property value from a component in Vue.js 2.0

I am currently working with a specific component that allows for date selection: <template> <div class="animated fadeIn"> <div class="col-sm-6 col-lg-6"> <datepicker class="form-control" :value="config.state.fromDate" ...

Unable to insert an array within a function

I've searched for the answer but couldn't find it - my array is not pushing to datahasil. How can I push the array hasil into datahasil...?? const data1 = await JadwalBooking.aggregate([{ $project: { "keterangan": "$keterangan", ...