The animation feature in Angular JS seems to be malfunctioning

Currently in the process of creating a slideshow using AngularJS, similar to the one found at this link, which includes navigation arrows (next and prev).

Here is the HTML code snippet:

<div class="carousel">
   <div class="left"><input type="button" value="Back" ng-click="slideBack()" ng-disabled="currentSlide == 0" /></div>
   <div class="content">
         <div class = "slide" ng-repeat="img in imgs | startFrom:currentSlide | limitTo:slidesSize" ng-animate="{enter: 'animate-enter', leave: 'animate-leave', move: 'animate-move'}">
    <img ng-src="{{img.url}}" />
         </div>
   </div>
   <div class="right"><input type="button" value="Next" ng-click="slideNext()" ng-disabled="currentSlide+slidesSize >= imgs.length" /></div>
        </div>

The relevant CSS code can be seen below:

.animate-enter, .animate-move, .animate-leave
{ 
    -webkit-transition: 1000ms cubic-bezier(0.250, 0.250, 0.750, 0.750) all;
    -moz-transition: 300ms cubic-bezier(0.250, 0.250, 0.750, 0.750) all;
    -ms-transition: 300ms cubic-bezier(0.250, 0.250, 0.750, 0.750) all;
    -o-transition: 300ms cubic-bezier(0.250, 0.250, 0.750, 0.750) all;
    transition: 300ms cubic-bezier(0.250, 0.250, 0.750, 0.750) all;
} 

.animate-enter {
      left: 400px;
      position:relative;
      opacity: 0;
}
.animate-enter.animate-enter-active {
      left: 0px;
      opacity: 1;
}

.animate-move {
      position:relative;
}
.animate-move.animate-move-active{
      left: -200px;
}

.animate-leave {
      left: 0;
}
.animate-leave.animate-leave-active{
      left: -100%;
      position:absolute;
}

Filter implementation for the slideshow:

angular.module('carouselFilters', []).filter('startFrom', function() {
    return function(input, start) {
        start = +start;
        return input.slice(start);
    }
});

Controller handling the slideshow functionality:

function carouselCtrl($scope, $http) {
  $scope.currentSlide = 0;
  $scope.slidesSize = 3;

  $http.get('carousel_images.json').success(function(data) {
        $scope.imgs = data;
  });

  $scope.slideNext = function(){
        $scope.currentSlide++;
  }

  $scope.slideBack = function(){
        $scope.currentSlide--;
  }


}

The animate-enter and animate-leave transitions are functioning properly, however, experiencing issues with the animate-move transition. Any suggestions or ideas would be greatly appreciated.

Thank you.

Answer №1

  • use "enter" when a DOM element joins the repeat list.
  • employ "leave" when a DOM element exits the repeat list.
  • utilize "move" when a DOM element transitions from one position to another within the repeat list.

I was inspired by an example I found on nganimate.org.

In my scenario, there is a collection of items displayed using ng-repeat.

line 21: <li ng-animate="'animate'" ng-repeat="name in names | filter:search">

In my stylesheet style.css, I followed the same CSS approach as you did.

To showcase the animation effect, I added a button that shuffles the li's around using _.shuffle.

<button ng-click="shuffle()">Shuffle the List</button>

It seems more like adding/removing elements from the repeat list rather than moving them physically. I hope this clarifies things.

Apologies for saving the incorrect version - http://plnkr.co/edit/ZXkwx7Skuy42ndWexMt0

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

Is there a way to horizontally align text in a div using center alignment?

Excuse me for what might seem like a silly question, but I am having trouble figuring this out. Edit: All I want is to horizontally center the text without affecting the image's position. The image should stay aligned with the baseline of the text. ...

Tips for testing an Angular factory function

I am attempting to run a test on a factory using protractor and angular.mocks Below is the code for the factory: angular.module('googlemarker', []) .factory('newMarker', newMarkerFactory); newMarkerFactory.$inject = ['$windo ...

Preventing Flash of Unstyled Content in ElectronJS Browser Windows

Upon creating a new BrowserWindow and utilizing loadURL to incorporate an html file within the renderer, there is a brief instance where unstyled content is displayed for approximately half a second before the css is loaded. window.loadURL('file://&a ...

Ways to Create a Webpage with a Single Color Palette

Struggling to update the background color on my webpage and hitting a wall. Even with content, the black background only extends as far as the content does. I've experimented with extending the content, using the body selector, and universal selector ...

Function of Directive LinkI hope this meets your

Looking for help with creating an ajax loader using directives. I encountered an error when trying to use the show and hide functions in the link function. elem.show is not a function at Object.fn (loaderDirectives.js:15) at Scope.$digest (angular.js:1181 ...

Navigating through certain JSON information in AngularJS

I am facing a challenge with handling article information stored in a json file, where each article has a unique id. The format of the json data is as follows: [{"title":"ISIS No. 2 killed in US special ops raid", "id":"14589192090024090", ...

Struggling to link variables and functions to an angularJS controller

When using the $scope object to bind functions and variables, and making changes accordingly in HTML, the code works fine. But when using a different object, it doesn't work as expected. Here is an example of a working code snippet: ...

In Angular, when a promise returns an "undefined" value, how does this interact with .NET

When I execute this code snippet, I am encountering an issue where the response returned is "undefined" instead of the expected value. Here is the code in question: $scope.SameNameFunction = function() { var payload = { itemname: $scope.EventD ...

What is the most effective method for incorporating ng-class with a single intricate condition?

I'm looking to combine ng-classes in my code. Can someone help me with that? ng-class="{removeBtn:'selected'}[resource.check_added_to_plan]" && ng-class="'lastSpan':($index+1)%3==0}" If the value of resource.check_added_t ...

Unique text: "Custom sorting of JavaScript objects in AngularJS using a special JavaScript order

I'm working with an array structured like this: var myArray = []; var item1 = { start: '08:00', end: '09:30' } var item2 = { start: '10:00', end: '11:30' } var item3 = { start: '12:00& ...

State dropdown in Angular dynamically updates based on the country selected

I am in search of a contextual state dropdown menu that is linked to the country, ensuring only relevant states are displayed. I have explored these two solutions for guidance in my project. Angularjs trigger country state dependency angularjs dependant ...

Monitoring individual elements of an array within an Angular service

Is there a way to monitor changes in an array element within a service? Let's consider the following scenario with CartController and ProductListService. Within the ProductListService, data is fetched as follows: /** * Fetch all the products in us ...

The CSS background shadow on one div behaves differently compared to the neighboring div

Currently, I am facing an issue where I have two divs positioned next to each other in a line. http://jsfiddle.net/A5Jc7/60/ The HTML structure is as follows: <div> <div class="box1"></div> <div class="box2"></div> ...

How come the inclusion of a DOCTYPE tag impacts the styling of my CSS?

I am puzzled why the code below renders correctly without any issues until I add a doctype declaration: <body style="margin:0; padding:0; background-color:#eeeeee"></body> <div id="HeaderContainer" style="background-color:#eeeeee; color:Bl ...

Developing a personalized data binding feature with AngularJS and utilizing ng-repeat

Looking to design a unique controller that can display multiple similar objects connected to a dataset structured like this: [{name: card1, values: {opt1: 9, opt2: 10}},{name: card1, values: {opt1: 9, opt2: 10}}] The goal is to showcase the name and one ...

The CSS3 Transform feature kicks in only after the window is resized in Mozilla Firefox

I have created a pure CSS3 parallax webpage by following the method outlined by Keith Clark and using a sample made by Carl Henderson (I can't provide a direct link to his codepen due to my lack of reputation). You can find the code in the main page, ...

Tips for creating text that wraps around an image in an editor

On my webpage, I am using an editor called Cleditor jquery plugin. The default setting allows me to insert images, but the text does not wrap around it. I attempted using vertical-align:top, but it did not resolve the issue: What CSS property should I ap ...

Discover the Magic of CSS Animation

I am not experienced in CSS animations and have limited knowledge about animations. I am trying to create an animation where a grey box slides down from the top line above the login/register section, but currently it only fades in. If anyone can provide an ...

Bidirectional binding of attributes in an Angular directive

I have developed a custom Angular Directive known as evoEventMirror. Its main purpose is to attach a jQuery event to an inserted element and apply a specified CSS style to the "root" element. Refer to the example below: <div id="#mydiv" evo-event-mirro ...

The addition of a slash between the hashtag and the anchor name by Fullpage.js is causing conflicts with ng-include

My experience with using fullpage.js on a simple site alongside angular directives has been met with an issue. When including a .phtml file, the anchor functionality of fullpage.js stops working as it adds a slash before and after the anchor name. UPDATE ...