Troubleshooting jQuery Dropdown Menu Animation Bugs

Take a look at this interesting fiddle: https://jsfiddle.net/willbeeler/tfm8ohmw/

HTML:

<a href="#" class="roll-btn">Press me! Roll me down and up again!</a>
<ul class="roll-btns">
<li><a href="#" class="control animated noshow one">Milk</a></li>
<li><a href="#" class="control animated noshow two">Eggs and Cheese</a></li>
<li><a href="#" class="control animated noshow three">Bacon and Eggs</a></li>
<li><a href="#" class="control animated noshow four">Bread</a></li>
</ul> 

jQUERY

$('.roll-btn').click(function() {

    var ctrls = '.control';

    if ($(ctrls).hasClass('noshow')) 
  {
    $(ctrls).each(function() {
       $(this).removeClass('noshow');
       $(this).addClass('fadeInDown');
    });
    } else {
    $(ctrls).each(function() {
       $(this).removeClass('fadeInDown');
       $(this).addClass('fadeOutDown');
    });
  }

});

This may seem simple, but I'm facing challenges in its implementation. Essentially, the "noshow" class acts as a toggle for the A elements. If it's not present, then apply the CSS animation to the A element. If the CSS animation is present, add another CSS element to conceal the A elements. I've experimented with delaying the "noshow" class and other techniques without success. While this example functions correctly on the first two clicks, it fails thereafter due to the absence of the noshow class being added. In essence, I need the noshow class to be included on the second click AFTER the completion of the CSS animation.

Answer №1

$('.roll-btn').click(function() {

  var ctrls = '.control';

  if ($(ctrls).hasClass('noshow') || $(ctrls).hasClass('fadeOutDown')) {
    $(ctrls).each(function() {
      $(this).removeClass('noshow');
      $(this).addClass('fadeInDown');
      $(this).removeClass('fadeOutDown');
    });
  } else {
    $(ctrls).each(function() {
      $(this).removeClass('fadeInDown');
      $(this).addClass('fadeOutDown');
    });
  }
});

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

Displacement occurs when the input tag is eliminated

After some trial and error, I have discovered that removing the input tag from the label causes a change in the layout height. I am puzzled as to why this is happening. Could there be a special reason for this height alignment issue when an input tag is pl ...

Do all descendants consistently trigger rerenders?

Recently, I was exploring the React new documentation here, where I came across this interesting piece of information: The context value mentioned here is a JavaScript object with two properties, one being a function. Whenever MyApp re-renders (for examp ...

"Encountering issues with getStaticPaths not generating any paths

I have a folder named data which contains a file called events.ts: export const EventsData: Event[] = [ { name: 'School-Uniform-Distribution', images: ['/community/conferences/react-foo.png', "/community/conferences/react ...

When json.parse encounters an undefined value at position 1

Currently, I am diving into learning express.js and my latest project involves creating a web app that can convert cryptocurrency to Fiat currency. Things have been progressing smoothly so far, but I've hit a roadblock when attempting to use json.pars ...

Creating a 3D object using three.js framework

When playing video games, I often notice a common pattern where hovering the mouse over an object triggers a gradient highlight around its 2D representation. To recreate this effect in my Three.js scene, I started by setting up the necessary raycaster vari ...

Repeating Elements with Angular and Utilizing a Touch Keyboard

Currently, I am developing a table with various fields and the ability to add new rows. The goal is to display all the inputted data at the end. This application is specifically designed for touch screen monitors, so I have created a custom keyboard for in ...

Error thrown in JavaScript when calculating the distance

I am currently working on calculating distances between two points, but I keep getting an error that says Uncaught TypeError: a.lat is not a function. function MapLocations() { var i = 0; var infoWindow = new google.map ...

The CSS method to conceal the initial list item is proving ineffective

I'm having an issue with my WordPress theme where I want to hide only the first li element but it's hiding all of them. Here is the HTML code I'm using: <div class="nav"> <ul class="nav-tabs nav-justified"> <li class="activ ...

Authentication through Proxy and requests from nodes

I am attempting to make a get request to a website via https using the request module. However, I am behind a proxy that requires authentication. Despite my attempts to add the authentication, the connection to the site fails. I have experimented with add ...

retrieving or submitting information using jquery and displaying the URL in the browser's address bar

So, I have a deadline looming tomorrow morning.. I'm currently working with jQuery, trying to load data from an external file. What I really need help with is figuring out how to load new data when I use $.post or $.get in jQuery. Sending a request ...

In the middle of one div, there are two additional divs positioned nearby

I am facing a challenge with positioning three divs within one container. I want one to be on the right, another on the left, and the third one at the center, but so far I have not been successful; <div id="durum3" style="width: 100%; height: calc(10 ...

React Native Child Component State Update Issue

In my code, there is a Child component that triggers a function in the Parent component. However, when the function is triggered, an error related to the setState method is thrown. Issue with Promise Rejection (id: 0): The '_this12.setState' i ...

Web browsers are displaying code rather than the page itself

I recently hosted a .Net application on my Local IIS Server. Unfortunately, I neglected to handle error cases in MVC, opting instead to utilize the IIS .NET Error for page redirection to a specific page. When errors occur, the ASP.Net error page shows up ...

What is the event in jQuery that behaves differently in Firefox Developer Browser compared to other browsers?

My observation revealed that the symbols "-" and "+" (not those on the numpad) yield different values. I conducted a comparison using this resource: http://api.jquery.com/event.which/ Please refer to this image for a visual of a Swedish keyboard layout: ...

Is your script tag not functioning properly with Promises?

Below is the code snippet used to dynamically append scripts in the DOM using promises. This piece of code is executed within an iframe for A-frame technology and it is generated using Google Blockly (Block-based coding). export const appendScript = asy ...

Encountered an error with the opcode during deployment of migrations

Encountering an error while running the truffle migration command, despite trying several solutions without success. PS C:\Users\Jatin\OneDrive - nsut.ac.in\Desktop\Truffle\web> truffle migration Compiling your contracts... ...

issue with jquery changes within a select dropdown in HTML

I'm facing an issue with a select option on my website. <select class="form-control" id="province_id" name="province_id"> Despite following your instructions, the code isn't functioning as expected. <scrip ...

What is the process for configuring a registry for a namespaced package using yarn?

Experimenting with yarn as a substitute for npm has been quite interesting. With npm, we usually rely on both a private sinopia registry and the official repository for some namespaced packages, since sinopia doesn't support namespaces. My .npmrc fi ...

"Exploring the use of conditional rendering in React to dynamically hide and show components based

I am currently immersed in the world of React/Redux, focusing on an e-commerce project. This particular application offers two payment methods: cash and card payments. On the product display page, both payment icons are visible. However, I am seeking a sol ...

Exporting Textures with Custom Offsets to GLTF from Three.js Scene

UPDATE: I was initially puzzled about exporting to obj and mtl formats, but then I stumbled upon the GLTFExporter.js in three.js which allowed me to successfully extract both the geometry and texture from my project. However, a new challenge arose with t ...