Angular - when removing items from ngRepeat, the remaining elements do not transition smoothly; instead, they abruptly snap or jump into position

Currently using AngularJS v1.4.8 with ngAnimate injected into my controller.

In the process of creating a dynamic list using ngRepeat, tied to an array. The addition and updating of items in the list function smoothly with animations working as intended. However, upon deleting an item from the list, the subsequent elements below it snap abruptly into place. Seeking a solution for these trailing elements to transition gracefully into position instead.

Just to emphasize, when removing an item, the elements that follow suddenly fill the space left by the deleted element. Desire is for them to elegantly slide into this void.

Attempted adjustments with max-height property, setting it as a fixed value for entry and then to 0 for exit. Unfortunately, no changes observed - no shrinking effect whatsoever.

Which section of CSS should address this issue?

  • ng.enter
  • ng.leave
  • ng.move (mild suspicion that drag&drop examples might not apply here)


View

This is how the HTML "list" is structured:

<div ng-repeat="cItem in commentData.comments" class="animate-repeat">

CSS

Present CSS setup utilized:

.animate-repeat.ng-enter,
.animate-repeat.ng-move
{
    -webkit-transition:0.5s linear all;
    -moz-transition:0.5s linear all;
    -o-transition:0.5s linear all;
    transition:0.5s linear all;
    opacity:0;
}

.animate-repeat.ng-leave
{
    -webkit-animation:0.5s fadeOut;
    -moz-animation:0.5s fadeOut;
    -o-animation:0.5s fadeOut;
    animation:0.5s fadeOut;

    opacity:1;
}

.animate-repeat.ng-enter.ng-enter-active,
.animate-repeat.ng-move.ng-move-active
{
    opacity:1;
}

.animate-repeat.ng-leave.ng-leave-active
{
    opacity: 0;
}


/* Applied across platforms - not displayed here */
fadeOut {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

Screenshots

Before deletion https://i.stack.imgur.com/67stW.png

During deletion https://i.stack.imgur.com/dBTrC.png

Answer №1

Give this a try:

.transition.ng-show, 
.transition.ng-hide
{ 
    -webkit-transition: 800ms cubic-bezier(0.150, 0.150, 0.850, 0.850) all;
    -moz-transition: 800ms cubic-bezier(0.150, 0.150, 0.850, 0.850) all;
    -ms-transition: 800ms cubic-bezier(0.150, 0.150, 0.850, 0.850) all;
    -o-transition: 800ms cubic-bezier(0.150, 0.150, 0.850, 0.850) all;
    transition: 800ms cubic-bezier(0.150, 0.150, 0.850, 0.850) all;
    position: relative;
    display: inline-block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space:pre-line;
} 

.transition.ng-hide.transition.ng-hide-active,
.transition.ng-show {
    opacity: 0;
    width: 0px;
    height: 0px;
}

.transition.ng-show.ng-show-active, 
.transition.ng-hide {
    opacity: 1;
    width: 200px;
    height: 40px;
}

.ng-slide{
  border: 2px solid blue;
}

Answer №2

To enhance your slide transitions, consider incorporating styles such as margin, absolute positioning, or transformations within a block with overflow hidden. Additionally, by including "track by" in your ng-repeat directive, you can implement reorder animations. Angular tracks items in an array by $index by default, so without track by, the third item may be rendered in the second position after deleting the second one. Providing Angular with a unique key to track items allows it to accurately update positions without unnecessary re-rendering. This should improve the flow of your animations.

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

Capybara testing integration for input fields using 'TextAngular' feature

Utilizing TextAngular for a sophisticated text input box within an AngularJS/ Rails setup. Conducting integration tests with Capybara/Selenium & Capybara-Webkit. Attempted to create a test that enters text into the text area, but have faced challenges in ...

Design Pattern of AngularJS/Bootstrap Application

Seeking guidance on structuring a small AngularJS application for a simple stock charts app. As a seasoned developer but new to AngularJS, I am looking for the best approach. App Overview The app includes a left-hand "nav" bar for adding and selecting s ...

Issue with combining md-grid-tile and md-button in Angular Material not functioning as expected

I've been trying to make a md-grid-list with md-grid-tiles into clickable links by wrapping them in an anchor tag or an md-button, but so far I haven't had any success. The element seems to disappear when I try this method. If anyone has any sug ...

Ensuring a DIV remains fixed in place for a specific number of scrolls

I'm looking to create a 'Page section' that remains in place while scrolling for a specific distance and then smoothly transitions to the next section. I've attempted to implement this within the child theme without success... Any sugge ...

Web page saving fails to preserve images!

Currently working on a PHP-based website that is utilizing the Zend framework and hosted on an Apache server. The folder structure within my www directory looks like this: +www | |_+css | | | |_images | |_js | |_images The issue I'm ...

AngularJS is throwing an error of "TypeError: Cannot read property 'then' of undefined."

Within an AngularJS project, I am aiming to retrieve user data from those who sign in and utilize this data within an HTML form. To achieve this, I have a script called sessionService.js that sends requests to the server and receives responses. The follow ...

CSS media query to center the logo on mobile screens

As someone new to CSS and media queries, I'm reaching out for help from the experts. My challenge involves positioning a mat-toolbar with a menu button and app logo. The HTML code in question is as follows: <div class="toolbar"> <mat-too ...

What is the best way to ensure a div element on a printed page has a space between its bottom edge and the physical paper, as well as a space between its top

Within my div element lies a collection of other div elements. These elements contain lengthy text that may span multiple pages. I am attempting to print this text starting 50mm from the top edge of every physical paper, and stopping 20mm before the edge o ...

Mysterious gap found between image and table

Hey there! I've been struggling with an unusual gap between a top image and a table on my website (www.tradecaptaincoaching.com). The table was created using . Despite spending hours on it, I can't seem to get rid of the huge 200 pixel gap that& ...

The 'else' statement within a for loop modifies the value within an array

Hey there, I have encountered a peculiar issue with the else clause in my conditional statement. It seems to be rewriting the value in the array even when it has already found a match. Any thoughts on why this could be happening? Check out the code snippet ...

Setting font sizes using CSS values according to the Shadow DOM root element

Summary of the problem: I am searching for a method to establish font size values based on an element inside a shadow dom relative to the shadow host, regardless of the parent element's font size within the shadow dom. I am looking for a solution sim ...

Executing a custom object function in AngularJS by using the ng-click directive

As I navigate my way through AngularJS, I find myself grappling with the concept of calling a custom method of an object and wonder if there's a simpler approach: https://jsfiddle.net/f4ew9csr/3/ <div ng-app="myApp" ng-controller="myCtrl as myCtr ...

Combining Javascript and Django for a powerful web development solution

Having trouble setting up JS on my Django web app, despite reading through the documentation and previous queries. Using the Django dev server with the following file structure: mysite/ __init__.py MySiteDB manage.py settings.py ...

How can the data controller of a model be accessed within a directive that has been defined with "this"?

I'm struggling with accessing data using a directive, especially when I have defined my models like this: vm = this; vm.myModel = "hello"; Here is an example of my directive: function mySelectedAccount(){ return { restrict: 'A&ap ...

Difficulty positioning CSS, aligning flex-box grid with floating text

My attempt to include an aside section is causing alignment issues with the navigation menu and the aside itself. The problem seems to be related to using float:left for the 200x200 images. I want the layout to be well-positioned like the expected image. I ...

"Duplicate content issue with ng-transclude causing element to render twice

Why is the transcluded directive displaying Name inside directive = Frank twice? I believed I had a good grasp on transclusion, but this specific scenario has left me puzzled. Check out this fiddle for more details <div ng-app="myApp" ng-controller=" ...

Filtering data in AngularJS by parsing JSON records

I have a JSON file containing restaurant information and I need to display the data by grouping them based on their respective address fields. For example, all restaurants with the address 'Delhi' should be shown first, followed by those from &ap ...

Media publications do not conform to the current trends

I'm currently utilizing the HTML-to-paper plugin to print my content on a printer. However, I've encountered an issue where it doesn't seem to apply any of the styles I've defined within @media print. The challenges I'm encounteri ...

Is it common for content to duplicate when using the 'position: fixed' property in CSS media print?

Consider the following div element: ... <div id='section-to-print'>CONT /*Content*/ </div> ... Accompanied by this CSS code snippet: @media print { * { -webkit-transition: none !important; ...

I am looking to showcase a series of icons linked together by connecting lines

I have successfully designed the layout and added icons, but I am facing difficulty in creating connecting lines between them. I attempted to utilize CSS borders and pseudo-elements, yet I cannot achieve the desired outcome. If anyone could offer a CSS-ba ...