AngularJS version 1.2 brings stunning animation effects to your web pages with the ng-repeat

Staggering Animations are amazing! However, I'm struggling to make them work without any user interaction.

I have a simple ng-repeat list:

<div ng-controller="controller">    
    <div class="category" ng-repeat="category in categories">
      {{category}}
    </div>
</div>

This is how it's defined in the controller:

var controller = function($scope) {
  $scope.categories = ['12345', '6789', '9876', '54321'];
};

Along with some CSS rules for the animation:

.category.ng-enter {
  -webkit-transition: 2s linear all;
  transition: 2s linear all;
  opacity:0;
}
.category.ng-enter-stagger {
  -webkit-transition-delay: 1s;
  transition-delay: 1s;
}
.category.ng-enter.ng-enter-active {
  /* standard transition styles */
  opacity:1;
}

Unfortunately, the animation does not play when the page loads. I tried adding a button to replace the categories array with random numbers, and then the animation works fine.

How can I make the animation work when a user first visits the page?

You can see a demo here: http://plnkr.co/edit/3zXENPbYA3cxJQ3Pyb34?p=preview

I've read suggestions about using $timeout() but that only resulted in an animation on the first item, which doesn't feel right.

Answer №1

The animation is intentionally disabled during the bootstrapping process, as explained in this GitHub issue #5130.

If you want to enable animations on page load, there's a workaround provided by lioli. Simply add this line at the beginning of your controller (make sure to inject the $rootElement):

$rootElement.data("$$ngAnimateState").running = false;

Here's an example Plunker demonstrating the fix: http://plnkr.co/edit/9ZZ3JBOCaRJ41ssczX6l?p=preview

If you're experiencing issues where animations only occur on the first item, it has been noted that this is a bug specific to the minified version of angular-animate (i.e., angular-animate.min.js). Switching to the unminified angular-animate.js appears to resolve the problem.

For more information on this issue, refer to these GitHub links: #8297 and #7547

Answer №2

Instead of using @runTarm's recommendation, another approach could be to load the data after the initial page load. For example:

$scope.items = [];

var items = '123456789'.split("");

$timeout(function() {
  $scope.items = items;  
}, 1000); // Wait 1 second before loading data

Updated example link

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

Connecting to Travel Events in a Page

When I try to bind a router event in the initialize method, I encounter some unexpected behavior: var View = Backbone.View.extend({ initialize: function() { router.on("route:test", this.update); }, update: function() { con ...

How can an HTML5 application be configured to enable access to intranet and local files?

It's a known fact that accessing the local path of a file added using a file input field or drag-and-drop is not possible even with the new FileAPI. Whether this limitation is good, bad, or ugly is not up for debate. The FileAPI specs clearly state th ...

Retrieving Gridstack ID's from JSON Source

I'm currently working on a gridstack project where I can manually add widgets with customized content, lay them out as desired, and then save the layout. The saved layout can be loaded back at any time to the last saved state. You can view a demo of t ...

Guide on how to import image data instead of an image using THREE.js in javascript

I wrote a JavaScript function that loads an image as a texture: var loader = new THREE.TextureLoader(); loader.load( 'textures/canvas1.png', function ( texture ) { var geometry = new THREE.SphereGeometry( 200, 20, 20 ); var material = n ...

Unlocking two features with just a single tap

I am currently working on a website for a kiosk, where the site transitions like a photoslide between each section. To achieve this effect, I have added a layover/mask on the initial page. The layover/mask is removed using a mouse click function. This is ...

Struggling to access the Angular Route

I am facing an issue where I can't seem to open the route "/d", while "/" is working perfectly fine. I have tried various troubleshooting methods but unfortunately, haven't been able to find a solution yet. var myApp = angular.module('myApp ...

Mozilla browser experiencing issues with mouse move event functionality

Here, I have a background image on the body and with the following script, when the user moves the mouse, the image in the background also moves. body { background-image: url('../images/1.png'); background-size: 98%; background-posi ...

Height fluctuations observed in Bootstrap Carousel

I am currently working with a react-bootstrap carousel component. The issue I am facing is that the carousel jumps when it scrolls due to the images having different sizes. If I try to fix this by setting the size with weight: 1309px and height: 730px, th ...

An error was encountered with Ajax and JSONP due to an unexpected token causing a SyntaxError

Currently attempting to retrieve information from the host at 000webhost The data is in JSONP format: { "categories": { "category": [ { "name": "Android", "parent": "Computer Science", "ID": "2323" }, { ...

By stopping clearInterval, the setInterval operation becomes solely dependent on time

I'm new to JS/jQuery and struggling with understanding how to stop a setInterval function after a certain time interval or number of executions using clearInterval. I know this question has been asked before, but I still can't figure it out. Cur ...

angular js: accessing nested json elements made easy

**How can I use Angular to display seeds or other data from "torrents" in HTML? ** Although this code appears to be working fine, it does not display any information when trying to show the seeds. HTML CODE <section class="list"> <article ...

I'm currently working on an if statement that checks for multiples of a specific number

I'm currently working on a coding exercise, but I've encountered an issue with my if/else structure and I can't figure out what's causing the problem. Below is the prompt for the exercise along with the code I have written: Your task ...

Looking for a specific phrase in the data entered by the user

I am dealing with data in ckeditor that looks like this: <p>test 1</p> <p>test 2</p> <p><img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsjHBYWICw ...

What is the best method for breaking down oversized controllers into several files within Express?

I’ve been working on an express application and so far, I’ve only had one controller file called users. This file includes different functions related to users like signUp, signIn, and getPersonalInfo. These functions are exported using module.exports ...

Enhance CSS delivery for the items listed below

Reduce the delay caused by rendering JavaScript and CSS above-the-fold. There are 16 CSS resources currently blocking the rendering of your page. This delay could be affecting the loading time of your content. To improve this issue, consider deferring or ...

In search of grabbing an image from a list item and relocating it to sit before the division tagged with class "event-title"

I am struggling with selecting each list element within the ul and moving the image inside the div class="event-details" above the div with the class="event-title". This adjustment is necessary for achieving the desired styling since the wordpress Event pl ...

Tips for displaying or concealing a particular form when a link is clicked, among multiple forms sharing the same class identifier

I am facing an issue with multiple forms and links that toggle them being appended to a page after a specific action. My goal is to have each link associated with a form toggle its respective form's visibility. However, I am currently encountering an ...

Load prior state when the value changes with UseState in NextJS

In the development of my e-commerce application, I am currently working on implementing filters based on category and price for the Shop page. To handle this functionality, I have established the initial state as follows: const [filters, setFilters] = useS ...

What is the best way to execute createReadStream(a stream) within a grunt plugin?

Struggling to implement a stream in a grunt plugin? Here's a comparison of code that works as a standalone node script: var fs = require('fs'); var sourceFile = 'testfile.log'; fs .createReadStream(sourceFile) .on(' ...

Why is MutationRecord[] organized as an array in MutationObserver?

I've been diving into the world of MutationObserve, and I've grasped most of it. However, one thing that's puzzling me is why the parameter requires an array. According to the documentation: An array of MutationRecord objects, detailing e ...