Exciting new animation feature in ng-repeat

I have implemented ng-repeat with custom styling and plan to expand the array by adding new items. Here is my code snippet:

// Custom JavaScript code 

var _app = angular.module("userApp", [])
_app.controller("usrController", function($scope) {
  $scope.usrList = [];
  $scope.adduser = function() {
    console.log($scope.newUsr)
    $scope.usrList.push({
      name: $scope.newUsr
    })
  }
})
/* Custom CSS styles */

.listItem {
  border: 1px solid #F00;
  background-color: lightgray;
  padding: 3px;
  border-radius: 5px;
  margin: 2px;
  width: 100px;
}
<!DOCTYPE html>
<html ng-app="userApp">

<head>
  <script data-require="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6e0f00091b020f1c40041d2e5f405a405e431c0d405c">[email protected]</a>" data-semver="1.4.0-rc.2" src="https://code.angularjs.org/1.4.0-rc.2/angular.js"></script>
  <link rel="stylesheet" href="style.css" />
  <script src="script.js"></script>
</head>

<body>
  <div ng-controller="usrController">
    <input ng-model="newUsr">
    <button ng-click="adduser()">Add User</button>
    <ul>
      <li class="listItem" ng-repeat="usr in usrList">{{usr.name}}</li>
    </ul>
  </div>
</body>

</html>

I want to enhance the user experience by adding a stackoverflow effect for newly added elements. Whenever a new element is added, it should display a fade or another animation effect like changing the background-color.

  • Any suggestions on how I can achieve this?

  • Can this be accomplished using only CSS3?

  • Is there a way to apply the same effect if an already rendered element is modified?

Answer №1

To achieve smooth animations in your AngularJS project, make sure to integrate the ngAnimate module and configure classes for ngRepeat.

Start by adding the module to your project (don't forget to include the necessary script tag as well):

angular.module("userApp", ['ngAnimate'])

Next, specify the desired transitions/animations like so:

.listItem.ng-enter {
    opacity: 0;
    transition: all .5s ease;
}
.listItem.ng-enter-active {
    opacity: 1;
}

Check out a live demonstration here: http://plnkr.co/edit/2QuyxMt4kiYkKeCoMGCL?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

I need assistance with this ajax/javascript/php

I am currently working on creating a dynamic chained list. The idea is to have the user make selections from the first four dropdown lists, and based on their choices, a fifth dropdown list should appear. However, I am facing some issues with my code as th ...

How can I change the orientation of a cube using d3js?

Seeking guidance on creating an accurate chart using d3js How can I rotate the SVG to display the opposite angle as shown in the image? Any recommended resources for achieving this desired result would be greatly appreciated. The provided code only disp ...

Aligning UL LI elements vertically for multi-line textORHow to vertically

I am dealing with a ul list that contains both single and multi-line li text. The issue is that the second line of the multi-line text starts at a different indentation than the first line. I need a simple solution to resolve this problem that works seaml ...

Why is my CSS Grid still not working correctly even though validation services have confirmed it is 100% correct?

After running my HTML and CSS through the validation services, everything seemed to check out fine. However, when I try to implement the grid layout using the CSS below, it doesn't seem to work as expected: body { display: grid; grid-template ...

Swap the image when hovering over it

Is it possible to modify this specific code so that a hover effect is triggered on mouseover? I attempted to look into similar questions and answers, but I found them difficult to understand. Here is the HTML snippet: <a href="RR.html"><img src ...

Ways to split a string using jQuery

I am working with a jQuery string array that contains the following elements: ["$1#Structure$2#Accounting$3Acc#$1Programming"] My task is to split the strings after the '#' symbol and provide the following result: ["Structure","Accounting","Ac ...

Step-by-step guide on defining a property within the ng-repeat's scope

My goal is to create a dynamic list of items that can be edited individually. Each item should have its own editing mode. Here's the code I'm using: <ul ng-controller="ItemCtrl"> <li ng-repeat="item in items"> <div cl ...

Jest - Test snapshot failure occurred following the inclusion of "</React.Fragment>"

I encountered an error message while running Jest. As I am not very familiar with using Jest, I would appreciate any insights on why this test is failing. Results: Jest test result: - Snapshot + Received - <span - className="icon icon-dismiss size-2 ...

Error: The route cannot be established within an asynchronous function

The following code snippet is from the api.js module, responsible for creating a test route: 'use strict'; module.exports = function (app) { console.log("before route creation"); app.get("/api/test", (req, res) => { ...

Utilizing shared functions defined across different controllers

Can I utilize the code within these controllers for other purposes? .controller('GenericController', ['$scope', '$controller', '$rootScope', '$dialogs', '$state', '$http', '$modal& ...

Expanding the size of a Three.js geometry in one direction

I've been experimenting with scaling geometries on the y-axis, but I've run into an issue where my cube scales both up and down. I found that using mesh.transformY to animate the cube up by half of the scaling value can create the illusion of the ...

Creating interactive avatars with Material UI and React to provide a dynamic user

I have developed a simple form validation application using react.js. Each user has a unique profile containing their personal information. I am looking to utilize the first letter of the user's name, for example Peter, where the letter "P" would be d ...

How to manipulate iframe elements using jQuery or JavaScript

Hey there, I have a simple task at hand: I have a webpage running in an iFrame (located in the same folder on my local machine - no need to run it from a server) I am looking to use JavaScript to access elements within this iFrame from the main page. How ...

The variable $http request is not defined in this context

When I perform a GET request on my backend to fetch JSON data, I am encountering an issue with storing a portion of the data in a variable for later use. Despite following similar steps in another controller where it worked fine, the variable always ends u ...

Utilizing Angular's $locationProvider in conjunction with ASP.NET MVC routing

Currently, I am managing routing in ASP.NET MVC using the RouteCollection class. However, my front end is built with Angular and there are instances where I need to update the URL using Angular's $location service while also supporting HTML5. To achie ...

Adjusting the height of one element based on the height of another element in multiple cases using jQuery

I am currently using jQuery to retrieve the height of one div and apply that value as a CSS property to another. Let's take a look at a sample layout: <div class="row"> <div class="column image"> <img src="image.jpg" /> < ...

Utilizing stream-based reading and writing to execute operations in MySQL database operations

I have extracted data from table tb_project_milestones and aim to insert this projectMilestoneRow into a table tb_xyz using streams. I referred to the documentation, but couldn't figure out how to execute it. Has anyone tried reading and inserting thr ...

What is the reason for the frontend indicating that the structure is not formed

When I try to retrieve a file stream from my Node.js (Express) backend and download it using the Range in Header, the frontend indicates that the response is NOT WELL-FORMED. Although I can receive data from the backend, when I attempt to download it, the ...

What is the best way to access data from outside a forEach loop in JavaScript?

I am trying to access the value of my uid outside of the foreach loop in my code. Can anyone assist me with this? This is the code I am working with: var conf_url = "https://192.168.236.33/confbridge_participants/conference_participants.json?cid=009000 ...

Converting a 3D model from Unity to three.js for seamless integration

I am tasked with building a human body model in WebGL using three.js, but I only have a Unity model. Is there a way to export the Unity model as an object or something similar for this purpose? ...