Multiple callbacks triggered by jQuery CSS transitions

I am experiencing an issue with my menu animation. I am curious as to why the slideDown transition is occurring twice. You can view the JSFiddle here.

<ul class=top-menu">
   <li>Item 1</li>
   <li>Item 2</li>
      <ul class="sub-menu">
         <li>Sub Item 1</li>
         ....
      </ul>
   </li>
</ul>

When hovering on the black vertical menu bar, it is supposed to slide out, revealing a sub menu that slides down.

I have written the following code to ensure that the menu first opens to the right, followed by the slide down animation for any selected sub menu.

$('#page-wrapper').one("transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd", function() {
    e.preventDefault();
    $('.active ul:first').slideDown('normal');
});

Could someone please explain why the slideDown function is being executed twice?

Any suggestions would be greatly appreciated.

Answer №1

To ensure smooth transitions, it is important to halt any ongoing animations before initiating a new one:

$('.currently-active ul:first').stop().fadeIn('slow');

Answer №2

Consider implementing a functionality where upon clicking span.menu-toggle-screen, you dynamically add a class (.random) to div#sidebar-wrapper. Additionally, when

$("div#sidebar-wrapper").hover(
  function(e) {
  /* Evaluate if the div wrapper contains the `random` class; if affirmative, halt the callback execution */


    if ($(this).parent().hasClass("toggled-2")) {

      //$('.active ul:first').stop().slideDown('normal');

      /* Initiate the sliding down of sub-menus once the main transition concludes */
      $('#page-wrapper').one("transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd", function(e) {
        $('.active ul:first').stop().slideDown('normal');
      });

    }
  },

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

Tracking the progress of jQuery ajax requests

I'm currently using jQuery $.ajax to send files over the internet. Is there a way for me to receive updates on the progress of the file transfer, and then adjust the settings accordingly? Below is my current implementation of $.ajax : $.ajax({ ...

Utilizing jQuery arrays to retrieve JSON object properties

Here is the JSON data structure I am working with: { "head": { "heading": ["header1", "header2", "header3"] }, "body": { "elements": [{ "header1": { "value": "value1" }, "header2": { "value": "valu ...

Excess padding in Internet Explorer 7 when a table is nested within a div tag

I have exhausted all potential solutions found on the internet and still cannot seem to solve this issue. Here is an example page that highlights the problem: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/l ...

"Encountered an issue with AJAX when attempting to access from a

On host1 with the domain , I have implemented an ajax structure consisting of: index.php (which includes the ajax functionality) config.php (for database connection) get_city.php The code snippet for index.php is as follows: index.php $(document).ready ...

What is the reason behind fixing an overflow issue simply by moving the mouse outside of a container in IE7 and HTML?

My webpage includes a series of questions, with each question being displayed or hidden based on the answer to the previous question. Occasionally, after toggling back and forth between questions, I notice that the final question appears below its designa ...

When using PHP code, the col-md-4 divs are positioned vertically instead of horizontally

I have written PHP code that seems to be working correctly, but the "col-md-4" divs are not aligning next to each other as expected. Instead, they appear one below the other. Could someone please assist me in identifying what I may have done incorrectly? ...

ways to undo modifications made to a value within an input field using jquery or javascript

$(document).ready(function () { //Highlight row when selected. $(function () { $('#Cases tr').click(function () { $('#Cases tr').removeClass('selectedRow'); $(this).addClass(&apos ...

Adding external JavaScript files that rely on jQuery to a ReactJS project

As a beginner in web development, I have a question regarding importing external JavaScript files in ReactJS. I currently have the following imports: import $ from 'jquery'; window.jQuery = $; window.$ = $; global.jQuery = $; import './asse ...

NextJs only displays loading animation once

Currently, I am developing an app using Next.js and I am facing a challenge with implementing a loading animation. The animation I am attempting to incorporate consists of three bouncing balls which display correctly. When I launch the Next.js app with n ...

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 ...

Elevate the size of the hero section

Is there a way to increase the height of my jumbotron without adding it in the class attribute, as it would affect responsiveness? I want it to look like this, but currently, it appears as this. Below is my code: Html: <div class="container"> ...

What strategies can I use to divide lengthy words in my Django application?

My username on the site is causing overflow outside of the content box, as shown here I tried adding h1, h2, h3, h4, h5, h6 { color: #44444; overflow-wrap: break-word;}, but it didn't work. Here is the code for the profile page: All CSS styles for ...

The __init__() function in Django encountered an error with the unexpected keyword 'user' being passed

Currently, I am working on establishing a password reset system using the default django libraries. However, I have encountered an error trace while trying to access the site for changing passwords (PasswordChangeConfirm). Internal Server Error: /reset/con ...

The fillOpacity and opacity properties appear to be malfunctioning

Note: While I understand that image masking can solve my issue, I prefer not to use it as it would require me to use my image as a background and could present accessibility challenges. I am specifically looking for solutions involving clip-path. Issue: T ...

A centralized navigation bar featuring a logo on the left side

I am trying to create a navbar with a centered layout and a logo floated to the left side. For inspiration, check out this example: http://www.bootply.com/98314 I would like something similar to the example mentioned but instead of left-floated items, I ...

Having trouble with Jquery Ajax call in IE8?

I have a dynamic data loading from the database, with each row containing links that perform various actions. Most of them work perfectly fine, but I've noticed an issue with the last one I added – it doesn't seem to be functioning properly on ...

Can you tell me about the feature called "Inspect Browser" box?

Can you identify the significance of this enigmatic purple box while inspecting elements in the browser's developer tools? It does not correspond to padding, margins, or borders, yet it seems to be occupying space within the designated div. [1]: http ...

Webkit causing complications with straightforward CSS3 animation

I'm currently working on a website and you can check it out here: Unfortunately, I've encountered an issue where the animations aren't triggering specifically on webkit browsers like Chrome and Safari: @-webkit-keyframes slideright{ 0% {tr ...

What is the most effective method for dynamically showcasing buttons in AngularJS?

Hello all, I'm currently learning AngularJS and I was wondering if anyone could recommend the simplest and most effective method for dynamically displaying links from AngularJS to HTML. I am looking to display a variable number of buttons in my HTML ...

Retrieve and manage information from a database using node.js and express

I am currently working on developing a jQuery mobile application and have set up a Linux server with node.js and express. The authentication process seems to be working properly, as well as the connection to another database server. However, I am facing a ...