Rapid jQuery Hover Bug

I am facing a problem with my sidebar. The issue occurs when I hover over the sidebar slowly, it works correctly. However, when I move the mouse quickly on it, everything gets messed up. How can I resolve this?

This is the HTML code:

<div class="sidebar">
        <ul class="insidenav">
            <li class="purple">
                <a href="" class="link purple"><span>Cloud Scholar</span></a>
                <ul style="display: none;" class="insidenavsubmenu">
                    <li><a href="">My Library</a></li>
                    <li><a target="_blank" href="">User Information</a></li>
                    <li><a href="">User Profile</a></li>
                    <li><a href="">Account Details</a></li>
                    <li><a target="_blank" href="">Change Password</a></li>
                    <li><a href="">Logout</a></li>    
                </ul>
            </li>
            <li class="green">
                <a href="" class="link green">
                    <span>Subject Metadata</span>
                </a>
            </li>
            ... (continue with other list items)
        </ul>
    </div>              

Here is the JavaScript code:

jQuery(window).load(function() {
    $('ul.insidenav > li').hover(function () {
        if ($(this).find('ul.insidenavsubmenu').length > 0) {
            $(this).find('ul.insidenavsubmenu').slideDown('1000');
            $(this).addClass('arrow-down');
        }
    },function() {
        if ($(this).find('ul.insidenavsubmenu').length > 0) {
            $(this).find('ul.insidenavsubmenu').slideUp();
            $(this).removeClass('arrow-down');
        }
    });
});

jQuery(window).load(function() {
    $('ul.insidenavsubmenu > li').hover(function() {
        if ($(this).find('ul.dubinsidenavsubmenu').length > 0) {
            $(this).find('ul.dubinsidenavsubmenu').slideDown('1000');
            $(this).addClass('arrow-down');
        }
    },function () {
        if ($(this).find('ul.dubinsidenavsubmenu').length > 0) {
            $(this).find('ul.dubinsidenavsubmenu').slideUp();
            $(this).removeClass('arrow-down');
        }
    });
});

This is the CSS code:

.sidebar {
    width: 18.75em;
    height: 200px;
    padding: 1.875em 0 1.375em 0;
    float: right;
    display: table;
}

.sidebar ul.insidenav {margin-bottom: 5px;display: inline;}
.sidebar ul.insidenav li.purple {background-color: #9b59b6;}
.sidebar ul.insidenav li.green {background-color: #6fba45;}
... (continue with styling for other list items and submenus)

Answer №1

This is a simple example that demonstrates proper functionality.

document.addEventListener('DOMContentLoaded', function() {
  Array.from(document.querySelectorAll('.accordion-header')).forEach(header => {
    header.addEventListener('click', function() {
      let panel = this.nextElementSibling;
      if (panel.style.maxHeight) {
        panel.style.maxHeight = null;
        this.classList.remove('active');
      } else {
        panel.style.maxHeight = panel.scrollHeight + 'px';
        this.classList.add('active');
      }
    });
  });
});
<html>
<head>
  <title>Accordion Example</title>
</head>
<body>

<div class="accordion">
  <button class="accordion-header">Section 1</button>
  <div class="accordion-panel">
    <p>Content for Section 1</p>
  </div>

  <button class="accordion-header">Section 2</button>
  <div class="accordion-panel">
    <p>Content for Section 2</p>
  </div>

  <button class="accordion-header">Section 3</button>
  <div class="accordion-panel">
    <p>Content for Section 3</p>
  </div>
</div>

</body>
</html>

Answer №2

Adjust the duration of slideDown to 500 for a quicker effect.

$(this).find('ul.dubinsidenavsubmenu').slideDown({duration:5});

If you need more guidance, check out this helpful resource.

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

At what point will the browser display changes made to css using jQuery?

When I run my JavaScript code in Firebug, it looks like this: tr=$(this).parent('tr'); tr.find('.img-delete').css('display','block'); However, I am unable to see the change reflected on the browser. Is there a wa ...

What could be causing the video not to display in landscape mode on the iPad Pro?

I'm having an issue with a standard HTML5 <video> on my website. The videos are working fine on most devices, however there is a problem specifically with the iPad Pro in landscape orientation. It seems to work properly in portrait orientation ...

Container items in flexbox that surpass the defined width

Hello, I am facing an issue where my container is exceeding the maximum allowed width of my flex container (with justify space-between). Essentially, I have divided my 3 children into equal parts of 33.33%, but the total width exceeds the limit: Image: ...

How to maximize efficiency by utilizing a single function to handle multiple properties in Angular

I have 2 distinct variables: $scope.totalPendingDisplayed = 15; $scope.totalResolvedDisplayed = 15; Each of these variables is connected to different elements using ng-repeat (used for limitTo) When the "Load More" button is clicked (ng-click="loadMore( ...

Basic selection menu layout

I have put together a basic menu for my WordPress site without relying on classes or IDs: <div class="main-menu"> <nav> <ul> <li> <a href="#" class="menu-link">home</a> ...

A guide to retrieving hyperlinks from an HTML table with Selenium

I am currently working on a Java and Selenium code snippet like the one below: public static void main(String[] args){ WebDriver driver; DesiredCapabilities caps; caps = new DesiredCapabilities(); caps.setCapability(PhantomJSDriverService ...

Combine the data retrieved from an AJAX call with the original source for autocomplete suggestions

$(function() { $("#search").autocomplete({ source: ["c++", "java", "php", "coldfusion", "javascript", "asp", "ruby"] }).focus(); $.ajax({ url: "source.php", success: function(result) { return result; ...

actions with frontend routing for CRUD operations

Imagine you are creating a simple CRUD todo application. Whether you choose to use Angular, React, or Vue for routing, the setup will be similar: /todos => see all todos /todos/:id => view one todo by id /todos/:id/edit => edit one todo by id /t ...

Why is my HTML a:active not functioning properly?

CSS Code for Highlighting Active Tab: // To highlight the current tab that the user is viewing // CSS styles for the active tab .HeaderTabs li.tab a { display: block; // Defines anchor tab padding: 12px 8px 12px 8px; } .HeaderTabs li.ta ...

Utilizing React across various sections of a traditional website

I have transitioned from using Angular 1.x to React in my server-rendered ASP.NET website built on Umbraco CMS. While I am familiar with creating single-page applications (SPAs) using create-react-app, I now need to incorporate React components in various ...

Refreshing data asynchronously with Ajax

I am currently using jQuery AJAX to retrieve a page named matid.jsp as shown below: var loadUrl = "matid.jsp"; $(".get").click(function () { $.get(loadUrl, function (responseText) { $("#result").html(responseTex ...

Unchanging bottom section with changeable information

I have a unique website design in mind that involves using an image as the background and placing the content within a box. View my website design here However, I am facing an issue with a specific page on this website. The page contains accordion buttons ...

Issue with the alignment of form input fields and buttons in Mozilla Firefox

Fixing Form Field Alignment Issue in Firefox After encountering and solving a form field alignment issue myself, I realized that the problem persisted in Firefox while displaying correctly in Chrome. Here's how I resolved it, although I am open to mo ...

Contrasting actions when submission occurs by pressing ENTER versus clicking the submit button

Incorporating an HTML form input element that utilizes a SearchBox from the Google Maps Places API for auto-completion is proving to be quite challenging. Within my JavaScript code, I have instantiated a SearchBox as shown below: var input = $('#spot ...

I am experiencing difficulty with the button not responding when clicked, despite trying to implement JavaScript and the Actions syntax

Currently, I am in the process of automating form filling. After filling out the form, there is an update button that changes color instead of clicking when activated. This alteration indicates that the xpath is correctly identified. I have attempted two ...

How can the ApolloClient authorization header be refreshed following a successful login process?

Essentially, within our index.js file, we establish the ApolloProvider authorization for conducting queries and mutations. import React from 'react'; import ReactDOM from 'react-dom'; import App from './App'; import ApolloC ...

What is the method for determining the number of arrays contained within a file?

I am working with a JavaScript file that looks like this: // main.js let array1 = ['first array']; let array2 = ['second array']; Currently, I have two arrays declared in my main.js file. Is there a method to determine the total ...

The Transition Division Is Malfunctioning

I've encountered an issue where I am trying to move a div by adjusting its left property, but no transition is taking place. Regardless of the changes I make to my code, the result remains the same. Below is the current state of the code. Can anyone i ...

rearrange index by moving all visible items to the front

I have a situation where I need to dynamically adjust the position of elements within a container based on a filter selection. Currently, the filter is working correctly but when elements are hidden, it leaves empty spaces in the layout. I would like to re ...

Tips for implementing the data.map function in Reactjs

I am currently exploring Reactjs with nextjs, and I am facing an issue with fetching data using the "map" function. Can anyone provide guidance on how to approach this? Below is my current code snippet: import { useEffect, useState } from "react" export ...