Animation not being triggered in Chrome when using the JQuery UI removeClass() method

Hey there stackoverflow community,

Edit: I've created a fiddle showcasing the issue area, as requested. Unfortunately, JSfiddle doesn't support JQuery UI animations, so the problem isn't visible there.

Check out the JSFiddle here

Edit 2: I've made 2 gifs to demonstrate the exact problem. The top gif shows Chrome with the issue, while the bottom one displays FireFox with the desired appearance. Notice how the Chrome gif animates on hover but snaps back without animation when the class is removed.

View the .gifs on Imgur

To clarify, the addClass method in JQuery UI has an additional parameter that should animate CSS changes based on the specified time. It works correctly for addClass(".hovered",300), but the same behavior does not occur for removeClass(".hovered",300) specifically in Google Chrome. In FireFox, it functions as expected. Here is the code snippet:

// Hover handler, adds hovered class to menu elements
$(".menu").hover(
// On hover
function()
 {
    $(this).addClass("hovered",300);
    currentHover = $(this).attr('id');

 },
 // When not hovering
 function()
 {
    currentHover = null;
 });

// Function to reset all un-flagged menu elements to default position
var animator = function()
{
    $(".menu").not("#"+currentHover).removeClass("hovered",300);
            $(".menu").animate();
};

// Sets interval for animator
   setInterval(animator, 200);

In case of confusion, the extra .animate() function is used to prevent queued animations when rapidly hovering over the menu elements. The animator function removes the hovered class from elements that are not marked as hovered or focused, and aren't currently in view.

Below is the CSS for the menu and any relevant parent elements:

html {
height: 4220px;
width: 100%;
background: url(space.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
font-size: 100%;
}

#menuWrapper {
font-size: 40px;
width:352px;
height:3935px;
position:absolute;
background-color:rgba(140,140,140,0.8);
}

#menu {
left: 35px;
height: 350px;
width: 200px;
text-align:left;
position:fixed;
color:#FFF;
padding:0;
cursor: pointer;
-webkit-user-select: none; 
-moz-user-select: none; 
-ms-user-select: none; 
user-select: none;

}

a.menu {    
font-family:Verdana,Verdana, sans-serif;
text-align:left;
position:absolute;
padding-left: 15px;
padding-right: 10px;
padding-top: 5px;
padding-bottom: 5px;
color:#FFF;
margin-top: 40px;
margin-bottom: 40px;

}

.hovered {
left: 95px;
}

Lastly, here's the HTML structure:

<div id="menuWrapper">
        <div id="menu">
            <a href="#homeSection" id="home" class="menu" unselectable="on">Home</a> <br />
            <a href="#aboutSection" id="about" class="menu" unselectable="on">About</a> <br />
            <a href="#projectSection" id="project" class="menu" unselectable="on">Projects</a> <br />
            <a href="#contactSection" id="contact" class="menu" unselectable="on">Contact</a>
        </div>
    </div>

Similar bugs have been reported regarding JQuery UI and Chrome in the past, however, I could only find "solved" issues. I am using the latest versions of JQuery, JQuery UI, Chrome, and Firefox for testing. Any help or advice would be greatly appreciated.

Answer №1

To start, eliminate the hovered class from all elements, and then assign it to the specific element with the following script:

$(".menu").hover(function() {
    $('.menu').removeClass('hovered')
    $(this).addClass("hovered");
});

Check out the Fiddle here

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

How to handle javascript and json file processing?

My json data structure is as follows: var json = { "A": { "A1": { "A11": "A", "A12": "B", "A13": "C" }, "A2": { "A21": ...

Argument not accepted in JavaScript

Currently, I am encountering a unique error message while working with a complex function that iterates through elements in my JavaScript onSuccess event. The error I am seeing is: exception encountered : {"message": "Invalid argument.", "description": " ...

Draggable Elements in jQuery for Scrolling Windows

When using jquery ui sortable, everything works fine without window scroll and my items stay contained. However, if I start sorting the items after scrolling the window, they jump to the same height as the window scroll and no longer stick to my mouse poin ...

VueJS - Building a Real-Time Timer with Begin, Halt, Continue and End

Currently, I am facing an issue with the resume function of my counter up feature. For instance, if the timer is paused at 00:00:03, and then, five seconds later the resume button is clicked, it should continue from 00:00:04. However, in reality, the time ...

Implement Next.js deployment on NGINX server with a 403 forbidden error

I am currently utilizing Next.js for the frontend and Django for the backend. During development, everything is functioning properly. However, when transitioning to production, I am encountering a 403 Forbidden Error related to /_next/static/chunks. It app ...

Store the token securely in your browser's localStorage and set up interceptors

Struggling with saving the token in localStorage and pushing it in interceptors to send it with all requests. Currently, passing user data and token from Symfony controller to frontend, but facing roadblocks in saving the token in localStorage and settin ...

Ways to constrain checkbox choices to only one within an HTML file as the checklist with the checkboxes is being created by JavaScript

I am working on developing an HTML dialogue box to serve as a settings page for my program. Within this settings page, users can create a list of salespeople that can be later selected from a drop-down menu. My current objective is to incorporate a checkbo ...

Expanding columns to reach the full height of the page

Struggling to create three columns within the colmask and threecol div classes, excluding the header and footer. Any suggestions? Check out the website at I've attempted setting the body and html tags to 100% height. I've also experimented with ...

ngx hierarchical dropdown

Is it possible that the 'disabled' attribute is not a recognized property of the 'ngx-dropdown-treeview' component? The ngxDisabledOnSelector property seems to be malfunctioning in my specific case. This is my code snippet: <ngx-dr ...

What are the best ways to incorporate EMs and percentages into responsive web design?

As I delve into the world of responsive design, I am eager to understand the most effective practices when it comes to utilizing em and percentage units of measurement. In a scenario where I set the font-size of the body to 10px, could this potentially le ...

Adding form information to a table using JQuery's prepend method

Can someone please help me figure out why the content from #tweet is not being added to a new row and prepended to #feed properly? When I try to submit the form in my browser, a row is created but then immediately disappears. I'm quite confused as to ...

How to Use Vanilla JavaScript to Fetch a JSON File, Convert the Data into an Array, and Iterate Through Each Object

Imagine having a JSON file called map.json: { "images":{ "background": ["images/mountains.png","images/sea.png"] } } The goal is for JavaScript to retrieve "images/mountains.png" from map.json and us ...

Enhancing User Experience with React-Redux: Implementing Subcategory Visibility based on Main Category Selection

How can I implement action logic to show and hide elements based on user interaction with main categories? Currently, all subcategories are being displayed at once, but I want them to be shown only when a user clicks on the corresponding main category. For ...

Writing a function to determine if an HTML element is present

Is there a way to create a function that checks for the existence of an element with a specific id? I have a list of IDs stored in an array: let CartArray = ["cart-0", "cart-1", "cart-2", "cart-3"]; This is the Java ...

I'm having trouble retrieving data from the server using the AngularJS $http.get() function. What am I doing wrong

Ensure that your question is clear and that your code properly showcases the issue at hand. Feel free to leave any questions or comments below for clarification. app.js var express = require('express'); var app = express(); app.use(express.sta ...

Capture a chart created with chart.js at full screen size across various window dimensions using html2canvas

I am trying to create a PDF featuring images generated by html2canvas. The main component on my webpage looks like this: https://i.sstatic.net/V7RVZ.jpg When I view the generated PDF in fullscreen mode, it appears as follows: https://i.sstatic.net/QW8Ct.j ...

Utilize jQuery to dynamically add a CSS class to a button

When using jQuery to create dynamic buttons, is there a way to add a CSS class to the button during creation without needing an extra line of JavaScript to add the class afterwards? Below is a example code snippet: $.each(data, function (index, value) { ...

Utilize CSS scrolling to present all items in a single line

Looking to showcase images in a horizontal line with scroll functionality? Unsure of how to achieve this and would really appreciate some guidance. CSS .img { max-width: 400px; position: relative; } .animal { float: left; background-color: #fff; ...

Drop-down functionality in Bootstrap Form becomes unresponsive after screen width is decreased

I recently encountered a strange issue with my simple Bootstrap form. When I resize my browser width to mobile size or view it on a mobile device, the form stops functioning properly. Unfortunately, I am unable to provide any specific code examples at this ...

Using JQuery UI to choose an item from a dropdown list using Selenium with C#

I'm a beginner with Selenium and I need to test a page that heavily utilizes JQueryUI. For a simple example that anyone can work on, let's take a look at the page. From the "Select a speed" dropdown, I want to select "Fast." My understanding ...