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

Display the elements of a div at a reduced size of 25% from its original dimensions

I'm currently developing a JavaScript-based iOS simulator that allows users to view their created content on an iPhone and iPad. This involves using AJAX to load the content/page into the simulator, but one issue is that the simulator isn't life- ...

"Discover the step-by-step guide for incorporating password reset functionality in AngularJS using UI router

I am currently working on an AngularJS application that includes login, registration, and forgot password features implemented using JWT. Additionally, I am using UI Router for managing various states within the app. When a user clicks on the "forgot pass ...

Conceal a plugin within a component from the main module of app.js

While this might be considered outdated, there are still many experienced front-end developers who have the knowledge to tackle it. I am attempting to avoid declaring a plugin in the main module of my application. Imagine I have structured the following ...

Retrieving information from a JSON document in IONIC with the help of AngularJS

Issue After using the ionic tabs template to create my first project with the ionic framework, I noticed that the data for friends and friend details is being pulled from an array list in the services.js file. However, I would like to instead fetch this d ...

Picture inside text area covering drop-down list

After making some adjustments to Bootstrap using a custom -theme.css file, I successfully altered the appearance of the dropdown menu. By removing the borders from the navbar and wrapping a header around it set to be fixed on top, everything seemed to be w ...

The functionality of Bootstrap Mobile css is most effective when navigating by scrolling downwards

I am experiencing a strange issue. I am using Ajax to load the Search form. The CSS is being applied correctly, but there is an unusual problem with the bottom margin. The bottom margin only appears when you scroll down in mobile view. When you load the f ...

altering the URL of an AngularJS application prior to its initial load

I have encountered an issue with the Instagram API where the result redirects to my app but Instagram does not accept URLs that include the "#" symbol. For example, http://localhost:3000/#/functionalists is not being accepted due to the "/#/". My app use ...

The button will continue to be enabled even if the textfield is empty

I have a task to implement a feature on a webpage where the submit button should remain disabled until all values are entered in the textbox. However, I am facing an issue where the submit button is already active when the page loads. .directive('pas ...

Obtaining the value of an item in an unordered list

Hi everyone, I have been trying to extract the value of <li> elements that display images horizontally. Below is the HTML code I am working with: <div id="layoutInnerOptions"> <ul id="navigationItemsContainer" class="layouts_list"> <l ...

CSS Transition not activating upon initial mouseover

My attempt at a simple transition is not working properly on Safari. I am trying to change background images from A to B on hover, but the transition is not smooth when I first hover over the element. Instead of gradually fading in/out, it instantly change ...

Is it possible to dynamically add a property to a directive I have created after the page has already loaded, depending on a specific condition?

In this case, the directive consists of an attribute (A). <input class="form-control" my-amount-field amount-min="5" amount-max="120" shouldBeingChecked="{{crCtrl.form.canCashM}}" name="myLimit" id="myLimit" ng-model="crCtrl.form.limits.cash.val" ng-b ...

Looking to subtly transition from the current webpage to the next one with a fading effect?

I'm looking to create a smooth transition between web pages on my site by slowly fading out the current page and fading in the next one when a link is clicked. $(document).ready(function() { $('body').css("display","none"); $(&a ...

Issues with Mouse Hover/Image Replacement

In this particular example, I am attempting to achieve a simple functionality where an image changes when the mouse hovers over it, and reverts back to the original image when the mouse is no longer hovering. However, despite my efforts, there seems to be ...

What steps should I take in modifying my existing code to use jQuery to set my div to a minimum height rather than a fixed height?

Could someone assist me in adjusting my div to have a min-height instead of a regular height? Whenever I click on the "Learn more" button, it extends past my div because the function is designed to set a specific height rather than an equal height. $.fn.e ...

Arrange records in ascending order by phone number when multiple are returned on the same date

Currently, I am working on an Angular application that is designed to keep track of tuxedo rentals. The main feature of the app is a table that displays information from an array stored in the controller. The initial task I completed was listing the items ...

The property 'join' is undefined for null values

I've recently started learning AngularJS, but I'm having trouble figuring out what's causing issues in my code. Despite trying various approaches, the outcome is always incorrect. <!DOCTYPE html> <html lang="en" ng-app="myApp"> ...

Tips for maintaining horizontal alignment of menu links

I am frustrated with the vertical alignment of my menus (home, photos, paintings) on my website. I want them to be displayed horizontally instead. Can someone please assist me with this issue? <style> body{background:black} li a{ white-space: ...

Implementing a JavaScript function that directs to the current page

I have set up my index page with a link that looks like this: <li onClick="CreateUser()"> <a href="#CreateUser">CreateUser</a> </li> When the "Create User" list item is clicked, the main page content is populated as follows: fun ...

The process of organizing and arranging the content that appears on a webpage is in

Seeking a solution to achieve a similar effect like this example. Wanting the sections to transition nicely when clicked on. Should I use a Jquery plugin or implement it with CSS? ...

AngularJS: Optimizing Image Loading for the Initial Page Load in AngularJS

Currently, I am working with a JSON object that contains image URLs which I am displaying using ng-repeat. However, I have encountered an issue where the images flicker when the page loads for the first time. I am looking to implement a preloader (CSS spin ...