Hover Effect on Navigation Menu for Special Events Only

I am trying to replicate the navigation menu effect of this website but with cleaner code. The current code I have was auto-generated from a PSD to HTML/CSS conversion tool, resulting in a lot of unnecessary code. While I can recreate most of the menu, I am stuck on implementing the hover-off effect for the Shop Now button only when the contact button is hovered over.

Do you have any suggestions on how I can achieve this toggle effect where hovering over the contact button turns off the Shop Now effect?

Below is what I have attempted so far:


    <ul>
        <li id="homeButton"> <img src="images/home.png" onmouseout="this.src='images/home.png'" onmouseover="this.src='images/homeHover.png'" width="115" height="55" alt="home" /></li>
        // Other menu items...
         <li id="contactButtonMenu"> <img src="images/contactButton.png" onmouseout="this.src='images/contactButton.png'" onmouseover="this.src='images/contactButtonHover.png'"  width="115" height="55" alt="contact" /></li>
        <li id="shopNowButton"> <img src="images/shopNowHover.png" width="114" height="53" alt="Shop Now" /> </li>
    </ul>

Here is my attempt on JS Fiddle: http://jsfiddle.net/GHHJM/

Answer №1

It's not too complex.

Create the menu using a <ul> element, as is commonly done today. Add a style called "hover" with a border to simulate highlighting. Apply the default class (with the border) to the last element. The rest should have normal styles for now. Remember, you can stack classes when working with styles like this:

<element class="firstclass hover otherclass">

Next, create a hover action:

$("li").hover(function () {
    $(elementtoputborderon).addClass("hover");
 },
function () {
    $(this).removeClass("hover");
  })

For the part where it turns off:

$("#idofcontactbtn").hover(function () {
    $('#idoflastelement').removeClass("hover");
 },
function () {
    $('#idoflastelement').addClass("hover");
  })

To achieve a "fade" effect on the last element, you could try something similar to this:

$('#lastitem').hover(function() {
    $(this).toggleClass('pretty-hover', 500);
  });

Answer №2

I have successfully resolved this using a simple and efficient method, focusing on the code for two button effects. I trust that this solution will be beneficial to those in need.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jQuery Hover</title>
<script type='text/javascript' src='jquery.js'></script>

<script  type='text/javascript'>
$(document).ready(function(){
    $(".contactButton").hover(function() {
        $(contactButtonMenu).attr("src","images/contactButtonHover.png");
            }, function() {
        $(contactButtonMenu).attr("src","images/contactButton.png");
    });
});

$(document).ready(function(){
    $(".contactButton").hover(function() {
        $(shopNowButton).attr("src","images/shopNow.png");
            }, function() {
        $(shopNowButton).attr("src","images/shopNowHover.png");
    });
});
</script>

</head>

<body>

<img id="contactButtonMenu" src="images/contactButton.png" alt"Contact Button" class="contactButton" />
<img id="shopNowButton" src="images/shopNowHover.png" alt="Shop Now" class="shopNowButton" />

</body>
</html>

Unfortunately, I am encountering compatibility issues with Firefox. Any suggestions on how to resolve this?

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

Struggling with modifying css attribute in a JQuery Chrome Extension

I have a basic chrome extension that I utilize on a specific URL to make slight adjustments to the page layout (such as color and position). Now, I am attempting to apply the same modifications to a new URL. The code I am using for both URLs is identical, ...

The split function is creating redundant values

Please help me with this issue I am facing while trying to split a string using split(). It's causing duplicate values which is frustrating. Can someone please assist me? The string I need to split is a comma-separated response from a database, and h ...

The presence of fs.existsSync as a function is not recognized when importing electron

I am currently developing a Vue and Electron application and I encountered a problem while trying to restart the application. Here is my code snippet: import { app } from 'electron'; export default { name: 'Home', methods: { re ...

Tips for transmitting data from a form to a server

I need assistance with sending form data to my backend server for a small website project. Although I have most of the backend work completed, I am struggling to figure out how to send the form data to the server. My goal is to send the data to a localhost ...

What are the steps to make the chosen title and its content active while deactivating the others?

I am currently developing a website for an educational institution that includes schools with subdivisions such as matric, CBSE, and state board, as well as a college. My goal is to create a user interface where clicking on a specific stream (such as matri ...

Encountering an issue with Angular when trying to add the urlRouterProvider

When I include the parameter ".config(function($urlRouterProvider)" in my config function, I encounter the following error: Uncaught object angular.min.js:6 (anonymous function) angular.min.js:6 (anonymous function) angular.min.js:34 q angular.min.js:7 f ...

Leveraging the power of AJAX, PHP, and JavaScript to display numerous status updates throughout an extended operation

It has come to my understanding that when using PHP, it is not feasible to send messages to the DOM using AJAX as the entire script must finish executing before the response becomes available. This leaves me with two possible solutions: Break down the le ...

The alternative condition for jQuery Color takes 17 seconds to respond

After extensive testing on all the browsers available on my computer, I implemented error handling and encountered no issues. The script is simple and works, but not as intended. When scrolling down, the bar should change to red, and while scrolling up, ...

The XMLHttpRequest fetches data before the page is completely loaded

I'm currently working on automating the search functionality of using XMLHttpRequest. However, I am facing an issue where the response is being received before the results finish loading. If you append a search term like "Layer", "Geoprocessor", "Le ...

Animating the movement of a div

How can I move the div "#menu" to the side when it's clicked on? I've tried the following code: <script> $("#menu").click(function(){ $("this").animate({ marginLeft: "+=250px", }, 1000 ); }); < ...

The validation error is triggered when using jQuery to add additional methods on select combo boxes

In the form I created, I am looking to validate specific dropdown combinations (where one field must have a selected value) involving selectpicker. To achieve this, I am utilizing jQuery validation along with additional methods. The script for validation ...

Unable to locate object for property 'setAttribute' and thus it is undefined

I am attempting to create an accordion using the code below. It works perfectly when the tags are placed together. However, I wish to insert an element inside a different tag elsewhere on the page. <dt> <li class="nav-item" i ...

Exploring an array in Angular 2 using TypeScript

Just starting out with typescript and angular2 and working through some issues. I have a form that needs to display results from an array of changing items, so I don't know the exact index of each result. Here is my scenario: In my form.html file: ...

Can the issue of mangling be avoided during .NET minification?

Currently, I am utilizing the .NET Bundling and Minification feature to bundle and minify the files for my application. While this method works well, I am interested in exploring alternative solutions due to its complexity. Specifically, I am attempting t ...

Tips for getting Vue's element-ui validateField() function to function correctly in conjunction with v-if?

Kindly observe the password fields. The fields for 'Password' and 'Confirm Password' are displayed upon clicking on the 'Change Password?' button. The provided code functions properly and effectively validates the form using ...

Sending files to the server through HTML5

Could someone assist me with uploading a file after it has been selected using HTML5? Here's the code snippet for selecting the file: <input type="file" .... /> The input field above allows you to choose a file, but I also need help with uploa ...

Different Ways to Customize Button Click Events in Angular 9 Based on Specific Situations

In my Angular 9 web application development, I frequently need to integrate Bootstrap Modals like the example below: <div class="modal" tabindex="-1" role="dialog"> <div class="modal-dialog" role="do ...

Swapping out images with a different image using angular.js

Need to switch out the image on my online exam paper with AngularJS and HTML at the end of the exam. When I started the exam, I included img id="online_start" in my code along with css to display an image on the page. CSS: #online_start{ background- ...

Despite being correctly linked in EJS and without any errors, the CSS is still not loading

Hey there, I'm facing an issue with linking a CSS file to an EJS file. I believe that I am connecting them correctly: <head> <title>Acres & Karats Calculator</title> <base href="/"> <link type="text/css" href="css/Acres ...

What is the best way to utilize Typescript when making queries to Firebase?

I have successfully integrated push notifications for my app using Firebase Cloud Functions. Now, I am looking to enhance the user experience by updating the app's badge count alongside the push notifications. I understand that this can only be achiev ...