Angular.js animation for element movement

I'm currently struggling to create a simple move animation.

I am aiming for a similar effect to the one shown in this example (taken from another SO question).

So far, I have managed to achieve this using the .animation() method.

This is essentially what I am doing:

.animation('.move-to-top', [function() {
    return {
        addClass: function(element, className, done) {

            var el = $(element);
            var top = el.position().top;

            el
                .addClass('move-to-top')
                .one('transitionend', function() {

                    setTimeout(function() {
                        el.css({
                            transform: 'scale(1.03) translateY(-' + (top+10) + 'px)'
                        })
                        .one('transitionend', function() {
                            setTimeout(function() {
                                el
                                    .removeClass('move-to-top')
                                    .css({
                                        transform: 'scale(1) translateY(-' + (top) + 'px)'
                                    })
                            }, 50);


                            el.prevAll('.timetracking-item')
                                .css({
                                    transform: 'translateY(' + el.height() + 'px)'
                                });

                        });

                    }, 100);

                });

        }
}
}]);

For the move-to-top class, it performs the following:

.move-to-top {
    @include vendor(transition, all 400ms ease-in-out);
    @include vendor(transform, scale(1.03) translateY(-10px));

    position: relative;
    z-index: 999;
}

The purpose of this animation is to:

  1. Add a class that scales and moves the item up slightly
  2. Move the item to the top using JavaScript
  3. Adjust the positions of previous elements to create space
  4. Remove the scaling added by the class

However, this approach relies on transforms, which may not be ideal. A cleaner solution would involve removing the transforms after the transitions are complete and physically moving the elements in the DOM.

An ideal scenario would utilize the combination of orderBy and ng-move, although this would require additional events like ng-pre-move and ng-after-move in ng-move.

Alternatively, if both addClass: fn() and move: fn() could be used together, with addClass firing before the element is moved, it would be more efficient. Unfortunately, this isn't possible when orderBy is applied.

The final option involves broadcasting an event from the .animation() function once all transitions are complete, and then sorting the array accordingly in the controller. However, this may lead to flickering due to the need to remove the style attribute from all items.

Are there any other suggestions or approaches that could be considered?

Answer №1

It seems like the pre-move will be happening soon in 1.3 here

Meanwhile, I have implemented ng-if to trigger a complete re-render of the list using Angular. It's working smoothly.

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

Sending an AJAX request to a REST service in order to submit the information captured in an HTML form

<html> <body> <form method="POST"> <label>username</lable> <input id="username" name="username" type="text"> <label>emailid</lable> <input id="emailid" ...

Tips for configuring formik values

index.js const [formData, setFormData] = useState({ product_name: 'Apple', categoryId: '12345', description: 'Fresh and juicy apple', link: 'www.apple.com' }); const loadFormValues = async () => { ...

"Uncaught Error: Unable to retrieve null properties" encountered while utilizing regex match in cheerio web scraping

Extracting text from brackets in HTML using regex: <dl class="ooa-1o0axny ev7e6t84"> <dd class="ooa-16w655c ev7e6t83"> <p class="ooa-gmxnzj">Cekcyn (Kujawsko-pomorskie)</p> </dd> <dd class="ooa-16w655c ev7e6t ...

The Material UI appbar fails to resize properly on mobile devices

I have added a material-ui appbar to the top of my website. Check it out here: Website Appbar However, when I resize the website to mobile size, the appbar does not adjust responsively to the screen. Here's how it looks on mobile: Appbar when in mobi ...

When THREE.js repeatedly loads and plays the same animated GLB file in a loop, only the final model that is loaded will

I'm attempting to create a loop of animated butterflies, but I'm encountering an issue where only the first or last butterfly actually animates. I suspect this is due to the need to clone the gltf.scene, but there's a known bug with cloning ...

Incorporate variable key-value pairs into a JavaScript array or object

Is it possible to add a key value pair to an existing JavaScript associative array using a variable as the key? I need this for JSON encoding and prefer a simple solution over using plugins or frameworks. ary.push({name: val}); In the above code snippet, ...

Adjust the size of every card in a row when one card is resized

At the top of the page, I have four cards that are visible. Each card's height adjusts based on its content and will resize when the window size is changed. My goal is to ensure that all cards in the same row have equal heights. To see a demo, visit: ...

Retrieving input field values in JS/Ajax without needing to refresh the page or click a button

Currently, I have set up a JavaScript function that submits data without refreshing the page or requiring a button click. The input field is located within tab #2 and triggers the JS function when the user stops typing. However, the issue arises when the ...

The useEffect hook in ReactJs is triggering multiple times

Encountering challenges while developing an Infinite scroll using ReactJs and Intersection observer API. Upon initial application load, the API gets called twice instead of once. This behavior may be due to strict mode, although not confirmed. Additionall ...

Combine and blur multiple background images using CSS blending techniques

I am currently working on a website, which is just a demo built in ReactJS: The issue I'm facing is related to the background. The idea behind the app is simple - it consists of 4 parts, with the top part displaying weather information without a bac ...

Using Firebase with Angular 4 to fetch data from the database and show it in the browser

Currently diving into Angular 4 and utilizing Firebase database, but feeling a bit lost on how to showcase objects on my application's browser. I'm looking to extract user data and present it beautifully for the end-user. import { Component, OnI ...

Storing a div in Javascript/HTML and concealing its descendants for later use

I have a div that I can select var selectedCell = null; $(".selectableBox").on('click', function (event) { selectedCell = $(this); } Later on, I need to hide one of the children inside selectableCell called selectableCe ...

Arrange containers into a tower?

Currently, I am exploring the concept of stacking boxes. While I have a solid grasp on how to stack them vertically from top to bottom, I find myself puzzled about how to stack them horizontally. Check out my vertical stacking method here See how I a ...

Creating a function that assigns an anonymous function which in turn returns another anonymous function

Can you explain the difference in JavaScript between these two code snippets? var reader = new FileReader(); reader.onload = (function (theFile) { return function (e) { loadData(e.target.result); }; })(file); reader.readAsText(file); a ...

Guide to importing an npm package into a client-side file

Having some trouble importing the js-search npm package into my client-side .js file. The documentation suggests using import * as JsSearch from 'js-search';, but I keep getting a Uncaught TypeError: Failed to resolve module specifier "js-se ...

Looking for the child route parameter in Ember - A comprehensive guide

Consider having 2 routes: /products - displays a list of products -/:id - displays details of a specific product When a URL is provided for the above routes, the /products route must be able to access the /:id parameter in order to highlight that prod ...

The Cascade of Ajax Dropdown Menus

I am currently working on implementing a cascading dropdown list using ajax. The idea is that when a user selects a degree from the first dropdown, the second dropdown should populate with schools offering that particular degree. However, I'm facing a ...

Establish the starting time for the timer and use the setInterval() function according to the seconds stored within the object

How can I configure the values of timerOn, timerTime, and timerStart to make the watch start counting from 120 seconds? Currently, the clock starts counting from 3 minutes and 22 seconds, but it should start from 2 minutes. You can find all the code here: ...

What could be causing the issue with my code attempting to conceal a parent div?

I attempted to follow the guidance found here, tweaking it to suit my requirements, but unfortunately, it's not producing the desired result. I am endeavoring to conceal a parent div that contains two child elements. These parent divs are part of a li ...

Retrieve the inner object within an object for tomorrow's date

I've searched for this information before but I can't find the answer - how do I access data in a data event to show data for the next date in the collection JadwalBooking? Data Schema: "keterangan" : "keterangan di rubah", "dataevent" : { " ...