Jump to content
Search Community

Animating list items after deleting an item

deglau test
Moderator Tag

Go to solution Solved by Jonathan,

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

I have a list of items in an array that are stacked above one another. When I delete an item I am able to call TweenLite.to () to slide it right and remove it from the DOM via an onComplete function (my Codepen is a simplified example of my actual scenario). By design, the item underneath the one that has been removed snaps up to fill the space. What I would like to do is animate that movement where the list item replaces the previously removed item.


My question may be a bit more fundamental in terms of how the DOM works, but is there a way for GSAP to capture that event and animate the move, or do I need to build a function that keeps track of each list item, its height and position, and manipulate all the items after the deleted one?

See the Pen IljhF by ChrisSki (@ChrisSki) on CodePen

Link to comment
Share on other sites

  • Solution

Hello deglau, and Welcome to the GreenSock Forums!


Do you mean something like this:


See the Pen KqJFf by jonathan (@jonathan) on CodePen


My example uses a GSAP special callback called onComplete. It is a function that is called when the animation has completed.


This could have also been done like in your example where you use setTimeout(). But in GSAP you could use delayedCall() which is far better.


Below taken from the GSAP Docs:




Provides a simple way to call a function after a set amount of time (or frames). You can optionally pass any number of parameters to the function too.

//calls myFunction after 1 second and passes 2 parameters:
TweenMax.delayedCall(1, myFunction, ["param1", 2]);

function myFunction(param1, param2) {
    //do stuff



TweenMax : http://greensock.com/docs/#/HTML5/All/TweenMax/

delayedCall() : http://greensock.com/docs/#/HTML5/GSAP/TweenMax/delayedCall/


I hope this helps :)

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...