What is the best way to maintain the CSS3 animation state following ng-animate?

Attempting to alter the state of a div using ng-animate along with CSS3 transitions.

The animations are functioning well with this particular CSS, except for the issue where the div loses its size and color once the animation is completed.

.fade-hide, .fade-show {                                                                                                                                     
  -webkit-transition:all linear 1s;                                                                                                                          
  -moz-transition:all linear 1s;                                                                                                                             
  -o-transition:all linear 1s;                                                                                                                               
  transition:all linear 1s;  
}                                                                                                                                                            
.fade-hide {                                                                                                                                                 
  opacity:1;                                                                                                                                                 
}                                                                                                                                                            
.fade-hide.fade-hide-active {                                                                                                                                
  opacity:0;                                                                                                                                                 
}                                                                                                                                                            
.fade-show {                                                                                                                                                 
  opacity:0;                                                                                                                                                 
}                                                                                                                                                            
.fade-show.fade-show-active {                                                                                                                                
  opacity:1;
  background-color: red;
  height: 200px;
}                

Have tried implementing animation-fill-mode:forwards; without success in preserving its state.

jsFiddle

Answer №1

In order to preserve the properties after applying effects, it is necessary to assign a separate class to the HTML object. This is because classes like fade-show and fade-show-active will be removed once the effect has finished.

Check out the updated demo here: http://jsfiddle.net/WufYs/1/

Here's the CSS code:

.fade-hide, .fade-show {                                                                                                                                     
    -webkit-transition: all linear 1s;                                                                                                                          
    -moz-transition: all linear 1s;                                                                                                                             
    -o-transition: all linear 1s;                                                                                                                               
    transition: all linear 1s;  
}    
.fade.fade-show.fade-show-active,
.fade.fade-hide {                                                                                                                                                 
    opacity: 1;
    height: 200px;
}                                                                                                                                                            
.fade.fade-hide.fade-hide-active,
.fade.fade-show {                                                                                                                                
    opacity: 0;    
    height: 0px;
}                                                                                                                      
.fade {
    background-color: red;
    height: 200px;
}

For more examples, visit nganimate.org website

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

Issue with Inline JavaScript in `href` tag not functioning correctly in Firefox

I am encountering an issue with this inline JavaScript not working in Firefox. I need to figure out how to make it function correctly in Firefox. <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <style> ...

JavaScript code that displays items in a shopping cart

I've set up the HTML and JS functionality for the cart, but I'm facing an issue where the JS doesn't render the cart items when the shop item is clicked. The styling in my HTML is done using Tailwind. If anyone could provide some assistance ...

Responsive design is achieved through the use of mobile media

I am seeking assistance with optimizing my website for mobile devices as it currently displays like the image below. Here are the solutions I have considered so far: Duplicating the 680 lines of CSS within the same document between @media only screen ta ...

Explore Dreamfactory's User Management features for apps with varying user roles and permissions

I am currently working on an application that requires user management with various roles to access different data views stored in a MS SQL Server database. To streamline the process, I am using dreamfactory to create a REST API for this data. My goal is t ...

Center the R Shiny showNotification on the screen

Currently, I'm exploring ways to customize the feature of showNotification() in Shiny. Link to example notifications My goal is to have the message appear at the center of the screen instead of the bottom-right corner. While it doesn't seem pos ...

Using Selenium in Python, identify and choose a class

Hello, I am currently working on automating a process using selenium, python, and GLPI. I have been struggling with selecting a user from a menu bar, despite trying various methods like linkText, cssSelector, and xpath. I suspect I may be doing something w ...

Organizing flex-items in a specific manner

My goal is to organize flex-items in a specific layout: To achieve this, I am referencing the following example: .Container { display: flex; overflow: hidden; height: 100vh; margin-top: -100px; padding-top: 100px; position: relative; widt ...

Creating a layout of <video> components in vue.js, complete with the ability to rearrange and resize them through drag and drop functionality

Despite trying numerous libraries and Vue.js plugins, I have yet to find one that meets all of my requirements. I am in need of creating a grid of video HTML elements that are draggable and resizable with a consistent aspect ratio of 16:9. Additionally, I ...

Sending auth0 token as a parameter in $http.get request in Angular

I am encountering difficulties when trying to attach the auth0 token to a http.get request for an API that requires the token. The token is generated upon user login and stored in the browser's local storage, which is functioning properly. The challen ...

The div is set to a position of absolute, causing the overflow-y property to be set to auto. As a

I am facing an issue with a div that has absolute positioning nested inside other divs. If you take a look at the code snippet below from http://jsfiddle.net/d8GYk/, you'll notice the styling properties applied to the div. <div style="position: ...

Align a header and a block of text in a vertical manner within a div

Struggling to align a h1 element and p vertically in the middle of a left-floated div, but they end up next to each other aligned vertically. Seems like table-cell display is the culprit, but not sure how to achieve vertical alignment without it. The curr ...

JavaScript code to make titles slide in as the user scrolls

Looking for a better way to make all titles slide in upon scrolling instead of coding individually? Consider using a forEach loop! Here's how you can modify the code below: function slideInLeft() { document.querySelectorAll('.subtitle-left ...

Tips for aligning text to the right and keeping it in line with another section

I have a code snippet and I'm aiming to align the caption for my "DigDug" game directly below the game itself, perfectly lined up horizontally. The id for the caption is "#DigCaption" and the id for the game is "#DigDug". Could anyone provide guidance ...

Ensure the webpage is set to have a minimum width of 1024 pixels

Is it possible to make a webpage that utilizes bootstrap, Angular 2x, and Scss stop being responsive once the screen width reaches 1024px? I would like the layout to stay fixed at this size and enable horizontal scrolling for users who resize their browser ...

Dividing a JSON string and incorporating them into individual tds using AngularJS

Currently, I am working on extracting values from a JSON string by splitting it at the ":" and displaying the two values in separate td tags. function testCtrl($scope) { $scope.response = {"name":["The name field is required."],"param":["Hobby: Coding", " ...

What is the method for executing a for loop in AngularJS without relying on HTML elements?

I'm creating an application in AngularJS where the structure requires me to execute a for each loop without using any HTML elements or div tags with ng-repeat. In Django, we typically use the following syntax: {% for item in list %} {{ item }} {% ...

How to Create a Bootstrap 4 Footer that is Perfectly Centered

Struggling to grasp Bootstrap 4 specifically, I am focusing on learning how to center my footer, which consists of 2 rows. Despite my efforts, I can't seem to get the entire footer centered properly. Below is the current HTML code I am working with: ...

The issue with the AngularJS filter seems to be arising specifically when applied to

My AngularJS filter isn't functioning properly when used with an Object. Here's the View: <input type="text" ng-model="searchKeyUser.$" placeholder="Search Keys" class="form-control"><br> <ul class="list-group"> <li cla ...

Utilizing JavaScript for parallax horizontal scrolling (identifying optimal 50% of screen)

I have successfully implemented this code for vertical scrolling: $('.flapleftclass').css('top',(0+(scrolled*0.5))+'px'); This method works well because I am referencing to the top position. However, when it comes to horizon ...

Iterating through data to showcase vertical columns for a specific time span of 3 years, highlighting only the months with available data

If data has been available for every month over the past 3 years, I need it to be displayed in a specific format. You can refer to this example fiddle for reference: https://jsfiddle.net/bthorn/ncqn0jwy/ However, there are times when certain months may no ...