Having difficulties implementing ng-animate to fade out elements with ng-hide

There seems to be some confusion around CSS3 animations and learning Angular animations has been quite frustrating for me. To demonstrate, I have created a Plunker here: http://plnkr.co/edit/VSIxhDy1qaVuF0j0pxjT?p=preview

Here is the CSS code used in the test scenario:

#wrapper {
    position: relative;
    overflow: hidden;
}

#wrapper, form, #wrapper > div {
    height: 400px;
    width: 400px;
}

#wrapper > * {
  transition: 10s linear all;
}

form {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
}

form.ng-hide-add-active {
    top: -100%;
}

#wrapper > div {
    position: absolute;
    left: 0;
    top: 0;
    background: #66F;
}

#wrapper.ng-hide.ng-hide-remove-active {
        top: 100%;
}

I am facing an issue where I want a form to slide up upon successful submission, with a success message sliding up underneath it. However, the under div just appears instead of animating. It behaves differently on Plunker compared to my code, where it initially shows, then vanishes with animation, only to reappear when the form is submitted. I have tried various solutions found online, such as using ng-animate="'name'" to create custom classes, but it does not work for me. The documentation also mentions an ng-hide-remove class that never seems to get applied.

Is there a benefit to using CSS3 transitions over creating custom animations with the animate module and utilizing jQuery? I believe keyframes might offer the most advantage. This challenge is making simple tasks, easily achievable in jQuery, exceedingly difficult...

Answer №1

When it comes to using ng-animate="'name'", keep in mind that this is primarily for Angular versions pre-1.2.

For animations of this kind, consider two states for every element involved.

  1. Visible
  2. Hidden

Imagine you have a wrapper containing a form and a message div for the animation. Start by setting up your HTML and CSS with the visible state in mind. When visible, both the form and the div should be inside the container and visible.

Here's an example based on your scenario (adjusted slightly for clarity):

#wrapper {
  position: absolute;
  height: 200px;
  width: 200px;
  top: 100px;
  left: 100px;
  border: 1px solid silver;
}

#form {
  position: absolute;
  top: 0;
  height: 100%;
  width: 100%;
  background-color: #DDFEFF;
  transition: all 1s ease-in-out;
}

#submitted {
  position: absolute;
  top: 0;
  height: 100%;
  width: 100%;
  background-color: gold;
  transition: all 1s ease-in-out;
}

In the visible state, both the form and the div are aligned to the top of the wrapper and fill the entire space, causing them to overlap. This won't be an issue as they shouldn't be visible simultaneously.

Next, define their hidden states:

For instance, when hidden, the form should be positioned above the wrapper:

#form.ng-hide {
  top: -100%;
}

Similarly, when hidden, the div should be positioned below the wrapper:

#submitted.ng-hide {
  top: 100%;
}

These adjustments should suffice, but some fine-tuning may be necessary depending on the version of AngularJS in use.

See a Demo here: http://plnkr.co/edit/FDJFHSaLXdoCK7oyVi7b?p=preview

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

Is there an issue with CSS rendering? Safari displays page headers and colors properly, but Firefox and Chrome are not showing the

I've been grappling with this problem for more than a week, but so far I can't seem to figure it out. It seems to be a CSS issue, but I can't pinpoint where I've gone wrong. Being self-taught, I would really appreciate any assistance. ...

What is the best way to enhance the appearance of the unordered list within the pagination design?

I'm struggling to apply styles to the ul within the Pagination, no matter what I try, it just doesn't seem to work! Here is an image for reference: https://i.sstatic.net/lQvPn.png I am trying to target the MuiPagination-ul class for styling ...

Preserve the checkbox-selected data in AngularJS for future reference

I am currently working on a project where I have records that are populated through an API call. After making some modifications, I need to save these records. However, I only want to save the selected records (which have a checkbox in front of them). How ...

Having issues with the tailwindcss transformation not functioning properly, but the problem seems to resolve when directly incorporating it into the

Lately, I decided to start utilizing tailwindcss and I have noticed that certain properties do not seem to function at all. However, when I incorporate them into my CSS directly, they work perfectly fine. Allow me to provide an example. const Step = styled ...

Having trouble replacing/using a relative image URL with JavaScript. Absolute path is functional, but relative path is not working

I have included what I believe are the crucial aspects in the fiddle. Currently, all my files are stored in a single directory. The CSS assigns a background image to the #slides div using a relative path. Then, with the help of JavaScript and an array, I i ...

What is the best way to define Bootstrap 5's CSS variables with the :root selector?

I am working with a Bootstrap 5 application that utilizes various web components, all styled with Bootstrap 5. I am looking to dynamically customize the theme within the parent component that integrates these web components. The basic structure of my setup ...

What is the role of z-index in relation to floating elements?

Why is it impossible to assign a z-index to a floated image and what are the reasons behind this limitation? ...

What methods are available for setting data to a field using CKEditor in a Protractor test?

Encountered an issue where I received a "element not visible" message in Protractor while attempting to input data into a field with CKEditor. This application is built with AngularJS. element(by.model("question.translations[lang.locale].answer")).sendKey ...

Can the Foundation 5 class label.inline be exclusively utilized for @media medium-up conditions?

I am attempting to achieve a specific layout for various media types, as shown below. On smaller screens: +----------------------+ | LABEL | +----------------------+ | TEXT INPUT | +----------------------+ On medium and larger s ...

ng-class not updating using a combination of object and string

I am just starting to learn angular js and I recently came across the ng-class directive. Below is an example of how I have used it: ng-class="[{'highlighter-row-Class' : (file.id == 1 && file.processed), 'bold-row-Class' : ...

Developing an AngularJS application using Maven within the Eclipse environment

We are currently working on a cutting-edge single-page application (SPA) where the front end is being built with AngularJS and the business logic is being handled by RESTful Web Services using JAX-RS. Our development environment consists of Eclipse as our ...

Arranging divs in a layout similar to tables cells and rows

Currently, I am developing a small game to enhance my Javascript skills. In the past, I utilized tables for displaying my content (images): Now, my goal is to switch from using tables to divs. However, I want to position them in a manner that resembles t ...

I constructed a table using a loop, and now I am interested in setting up a click event for each individual cell

for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { string empCode = ds.Tables[0].Rows[i]["EMP_CODE"].ToString(); string empName = ds.Tables[0].Rows[i]["EMP_NAME"].ToString(); string gradeCode = ds.Tables[0].Rows[i]["GRADE_CO ...

Transform a jQuery tree plugin into an AngularJS directive

I have utilized the JQuery tree plugin in a past project and you can find it at the following link: Currently, I am looking to convert it into an AngularJS Directive. Can anyone provide assistance on how to accomplish this? ...

Guidelines for Document State

I am looking to develop a straightforward directive that can show the status of a document. Currently, I have achieved this functionality through the controller without using a directive. However, my goal is to create a reusable directive. https://i.sstat ...

Ways to define a variable based on a CSS class attribute?

I need help figuring out how to create a variable in my script that is defined by the width attribute of a CSS class. The snippet I have currently doesn't seem to work as expected. var dist = $('.nav').css(width()); The goal of my script i ...

Enhancing Angular $http requests by including a content-type header

I am currently attempting to send an HTTP request with the code snippet below: var editCompanyUrl = 'http://X.X.X.X:YYYY/editCompany'; var userId = localStorage.getItem("UserId"); var token = localStorage.getItem("Token"); var companyId = localS ...

Will opting for only Jquery over AngularJS enhance the IE compatibility of an application?

I am currently working on an application in AngularJS that includes a specific page for users who are using Internet Explorer 8 (or older versions). If I were to use solely jQuery instead of a combination of Angular and jQuery (as Angular typically requir ...

How to keep an image anchored at the bottom of the page without overlapping other content

I'm trying to have a logo image stay fixed at the bottom of a navigation drawer, but when I use absolute positioning and set it to the bottom, it overlaps with the list items on shorter devices. When the scroll bar appears due to shrinking the browser ...

Guide to aligning text vertically in a column alongside an image using Bootstrap 5

I have been using the Bootstrap 5.3.2 grid system for most of my website. I am trying to create a layout with an image on the left and text on the right. However, I am facing an issue with aligning the text vertically in the column. Is there a way to achie ...