ngAnimate removeClass behaving unexpectedly

Recently, I've been delving into the ngAnimate module for AngularJS version 1.2.14

When employing $animate.addClass, everything seems to function as expected with the ng-animate, -add, and -add-active classes seamlessly added.

However, my struggle arises when trying to utilize $animate.removeClass, which appears to only execute an elem.removeClass equivalent. This results in none of the animation classes being applied during removal, like ng-animate, -remove, or -remove-active.

To illustrate this issue, I have created a plunkr that showcases the problem:

http://plnkr.co/edit/DIQSthOFxooVDSqO2KKQ?p=preview

Although I can manually code the removal methods, my preference would be to rely on the Animate directive.

Answer №1

To ensure proper animation, it is important to define the transition on the element's class itself rather than on the class being added or animated.

This allows $animate to recognize that a transition has been applied to the class and animate accordingly. Otherwise, adding or removing classes would all occur simultaneously without any animation taking place.

For more information, please refer to this example

CSS Classes:

.classname {
  /* The class of the element you want to animate */
  /* Its default state (invisible). */
}

.classname.visible-class-add {
  /* Any preparation needed before animating */
  /* This is where the transition property should be defined. */
}

.classname.visible-class-add-active{
  /* Additional styling during animation (may not always be necessary) */
}

.classname.visible-class-remove {
  /* Preparation for removal, possibly same as .visible-class-add */
}

.classname.visible-class-remove-active {
  /* Style changes during removal animation (usually not required) */
}

.classname.visible-class {
  /* The visible state after animation. */
}

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 can CSS be used to make an element completely move off the visible screen?

Imagine if I had a div that was positioned outside of the visible area of the computer monitor screen. When using CSS transitions to move it to a specific position, it would create an effect of the element slowly moving in from outside of the screen. Add ...

Tips for adjusting the font size of choices within the Material UI autocomplete component

Hey there, I'm currently working on a project using the Material Table and I'm looking to adjust the font size of the options in the Material UI Autocomplete. Any tips would be greatly appreciated! Thanks https://i.sstatic.net/ZM17w.png import R ...

JavaScript dynamic onclick method not functioning as expected

Greetings! I'm currently trying to set up a heading tag with some text inside of it. var d = document.createElement("h5"); d.innerHTML = "Dungeon"; Then, I am attempting to add an onclick listener. d.onclick = function(){myFunction()}; Unfortunate ...

Guide on using jQuery to dynamically update a section of an ejs template following an AJAX request in ExpressJS

I'm currently struggling to figure out how to dynamically update a portion of the DOM using EJS after a jQuery ajax call. The issue arises with a live search feature that successfully sends a request to the server, searches the database, and returns a ...

What is the proper way to select the <ul> element within an FTL template?

Can someone provide guidance on how to target a <ul> container within a freemarker template using JavaScript? My goal is to display the content of this specific <ul> element in my FreeMarker template on the web page. Any suggestions on how I ...

Error message encountered in Quagga JavaScript barcode scanner: "Uncaught TypeError: Quagga.init is not defined."

I'm currently facing a challenge with implementing barcode scanning functionality into my website using vanilla JavaScript. I've been trying to utilize the Quagga JavaScript library, but I seem to be stuck at the initial step. Here's the cod ...

What is the method for obtaining the angle in a CSS3 rotate transformation?

In my current code, I am setting the rotational angle of an element using the following: $('#1-link-2') .css('height', length) .css('-webkit-transform', 'rotate(' + angle + 'deg) ...

PHP unable to execute Javascript alert box

I am having trouble getting an alert to display when a user is redirected to the login-redirect page. Instead of showing the alert, it seems to bypass it and takes the user directly to the login-redirect page. Below is the code snippet: <script type=" ...

The output from a spawned process behaves oddly when it is being piped

I have a goal to convert the session of a process execution into JSON (similar to [{ type: 'stdout', data: 'What's your name?' }, { type: 'stdin', data: 'Alex.' }, { type: 'stdout', data: 'Hi, Ale ...

Can the color of text be adjusted (to either white or black) based on the background color (in any color and format)?

To achieve a text color that contrasts well with any background, I need to make sure it's either black or white. The background in my app can vary in color and format, so finding the perfect solution has been challenging. Using mix-blend-mode doesn&a ...

How can I correct the error in accessing state data with a getter and displaying the outcome in a component?

I am relatively new to vuejs 3 and vuex 4. I'm currently attempting to create a simple getter, but when it didn't work as expected, I resorted to using console.log to check the output. The result that appeared in the console was: ComputedRefImpl ...

Using hooks for conditional rendering

Background Information : My current project involves creating a form using hooks and rendering components based on the step. Challenge Encountered : I received this error message: "Error: UserFormHooks(...): Nothing was returned from render. This usually ...

Verify the presence of an email in the database utilizing a custom express-validator for node, express, and mysql

//Endpoint to update the user's email address. apiRouter.post('/update-email', [ check('newEmail') .isEmail().withMessage('Please enter a valid email address') .custom(newEmail=> { db.query(`SELECT user ...

Angular Directive for bootstrap-wysihtml5 not updating properly after changes

I am facing an issue with getting the change event to fire correctly while using wysihtml5 with an Angular directive. Here is the directive I have set up: app.directive('wysiwyg', ['$parse', function() { return { restrict: "A", ...

Guide to repositioning elements and fixing the functionality of the hamburger button: [ HTML & Bootstrap ]

Looking for help with creating a navbar for a website using HTML and Bootstrap. Need to move the header and link to the ends of the navbar and ensure that the hamburger button displays correctly on different screen sizes. Here's how it looks on deskt ...

When opening a dialog at the bottom of the page, the window will automatically scroll to the top

I'm encountering an issue with a page that has a width exceeding 100% (2000px). Whenever I click to display a dialog from a button located at the end of the horizontal page, the window automatically scrolls back to the beginning of the page before sho ...

The Model.findById() function is producing an undefined result

I am currently working on implementing a favorite toggle feature that saves favorites in an array. I have created a Schema and a router for this functionality. However, when I attempt to test it on insomnia, I am receiving 'undefined' in my conso ...

Ensuring a div remains perfectly centered

Currently, I am new to HTML and still in the process of learning. I am facing a challenge in centering a button within a div, and I have been using margins to position it. While this method works well when the window is fullscreen, the button's positi ...

Encountering an issue with core.js:15723 showing ERROR TypeError: Unable to access property 'toLowerCase' of an undefined value while using Angular 7

Below, I have provided my code which utilizes the lazyLoading Module. Please review my code and identify any errors. Currently facing TypeError: Cannot read property 'toLowerCase' of undefined in Angular 7. Model Class: export class C_data { ...

Enhancing game menus for various mobile screen sizes

I've noticed a consistent pattern in the games I download from the Google Play Store - they all have a background image at the menu with clickable buttons. When testing these games on different devices, I found that the backgrounds didn't stretch ...