Animating the reordering of slides in Angular using ng-repeat

I implemented a carousel slider in Angular utilizing ng-repeat with orderBy:'id'. However, I encountered an issue where the id changes when clicking the next slide button.

Check out my JSFiddle here

Within a div, I have ng-repeat:

<div class="slide" ng-repeat="slide in slides | orderBy:'id*1'">
    <p>
      {{ slide.value.name }}
    </p>
</div>

In addition, I've created a function to sort the new item list:

$scope.nextSlide = () => {
  let items = $scope.slides
  let countItems = items.length

  for (let i = 0; i < countItems; i++) {
    let z = items[i].id % countItems;
    items[i].id = z + (countItems - 1);
  }
}

The problem I'm facing is that the animation occurs first, followed by reordering of the scope and a blink to the new slide. Any suggestions on how to animate reordering in ng-repeat?

Answer №1

Have you thought about organizing the slides before advancing to the next one? This way, the initial order feels more familiar and the rearranged slides are revealed with each click...

I'm just not sure why you'd choose to reorder during the "next()" function.

Answer №2

It appears that the approach you are taking to address the animation issue may not be correct. Imagine having 2 items visible at all times. 1 | 2 | 3 | 4

When the next button is clicked, the following should occur: - The items should slide to the left (animation) - AFTER the animation completes, reordering of items (placing 2 at the back) AND simultaneously realigning the list should take place.

In your brief demonstration, it seems you may have overlooked centering the list properly. The effectiveness of this process might also hinge on how the animation itself is being executed.

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

trigger jquery popup from server-side code (ASP.Net VB)

Within my code, I have created a div element which serves as a popup message: <div class="info message"> <h3>Informa&ccedil;&atilde;o</h3> <p>Mensagem informativa.</p> </div> In addition, ther ...

The flow of the DIV elements is not functioning as expected

I'm struggling with positioning div classes in the normal way. I tried to create DIV boxes like this: li { width:200px; height:200px; background:red; float:left; list-style:none; margin-right:20px; margin-bottom:50px; ...

Troubleshooting: Angular 6 Renderer2 Issue with Generating Dynamic DOM Elements for SELECT-Option

Currently, I am attempting to dynamically create a select option using Renderer2. Unfortunately, I am facing difficulties in creating the <Select></Select> element, but I can confirm that the <options> are being successfully created. Due ...

Putting AngularJS controller through its paces using Jasmine

Here is the code for my NewPageCtrl.js file: angular.module('NewPageCtrl', []).controller('NewPageController', function($scope, $document) { $scope.showMe = false; }); And here is the content of test.js: describe('NewPageC ...

How to Use JQuery to Disable Controls or Background on an ASPX Page

I have implemented a code to display a dialog box for confirming a delete action. The code works fine, but the issue is that when the dialog box pops up, it doesn't disable any controls on the ASP.Net page. This allows me to interact with other contro ...

Recommend the application designed specifically for your web platform

Recently, I came across an announcement in an Apple Keynote about a new feature that allows users to seamlessly promote their native app from within their web service. An example was provided involving a restaurant table reservation system. When users acc ...

Creating a functional component in React using TypeScript with an explicit function return type

const App: FC = () => { const addItem = () => { useState([...items, {id:1,name:'something']) } return <div>hello</div> } The linter is showing an error in my App.tsx file. warning There is a missing return type ...

Take off the wrapping from the package

I need help with my code on how to remove the wrapper span tag without removing the text. <ul> <li> <a href="#"> </a> <ul> <li> <a href="#"> ...

What could be the reason behind the error message "Java heap space exception in Eclipse" appearing while trying to use JavaScript autocomplete?

Whenever I attempt to utilize a JavaScript template on Eclipse, the program always freezes, displaying an error message stating: "Unhandled event loop exception Java heap space." To troubleshoot this issue, I initiated a top command in Ubuntu for both the ...

Selecting list items using the up and down keys in JavaScript/jQuery

As the search terms dynamically populate a list of items, I am looking for a way to make the list items selectable/focused using the up/down keys and hide the dropdown with ESC key. <form> <div> <div class="field"> & ...

Reading data from Firestore in Next.js

I came across a Next.js starter that retrieves data from Firestore v9, but it only displays the data after a click event. How can I modify this code in Next.js to automatically show the data without needing to click? import { db } from '@/lib/firebase ...

What is the best way to conduct a conditional check across all subsequent visible rows of a table?

When a user clicks inside the text input field and presses either the down or up arrow keys, my JavaScript function is triggered. The purpose of this functionality is to search table values and allow the user to select one by pressing the arrow keys. Every ...

Tips for passing a timestamp to a Postgresql DB using a Button in a Form instead of a traditional rails time_select box

I am currently developing a CAD App in Rails 4 with Ruby 2. The goal is to provide users with a button on the screen to log an on-scene time and clear scene time, especially since most users will be using touch screen computers. Instead of using the defaul ...

verifying the string's value within the ng-if condition

Currently, I am trying to assess the value of a property within an object and comparing it with string data. <div ng-if="results.dataType === 'textTable'"> The content is meant for display in a table. </div> At present, all d ...

What is the best way to customize the styles of a reusable component in Angular2?

I am working with a reusable component called "two-column-layout-wrapper" that has its styles defined in the main .css file. In another module, I need to use this component but customize the width of two classes. How can I override these styles? import ...

Utilizing Bootstrap 4 to Position an Image Amidst Two Card Elements

Looking at the bootstrap 4 card documentation page in the Images > Image Caps section, you'll find two examples provided. In these examples, the image can be positioned either at the top or the bottom of the card block, with the .card-block div eit ...

Can you please specify the type of values being entered as input?

Query: How do I identify the data type of the value entered in an input field? Whenever I use typeof, it always returns string unless the string is empty. I searched various forums extensively but couldn't find a solution. Can someone assist me with t ...

Error message: The callback function provided is not valid

While trying to improve my searching and updating functionality, I developed a method as shown below: mergeAinBbyAttr: function(a, b, attr, val, cb) { async.forEach(a, function(itemA, callbackA) { async.forEach(b, function(itemB, callbackB) { ...

Using React-router and an Express server on the same port

Currently, I am in the process of building a website that utilizes react and react-router for the frontend, along with express for the server side. In order to establish session based authentication, I have incorporated express-session. However, the only m ...

The request returned a 404 (Not Found) error message when trying to navigate using AngularJS

Currently, I am working on building a straightforward application using Ionic and Angular. To test my progress locally, I have set up a simple server by running Ionics ionic serve command. Below is the snippet of my playlist.html code, where I intend to s ...