Jump to content
Search Community

Tricky Filterable list animation

chrisk2020 test
Moderator Tag

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 design I am trying to translate into an animated element. The design dictates a few things I am struggling to achieve nicely with GSAP. (I'm sure this is due to my brain and not GSAP).

 

First up here is a codepen of what I'm trying to achieve with no animation just using .show() and .hide() :

 

It is a filterable listing of floors of a building showing apartment types by bedroom number. If a floor has no children it is hidden completely and the first floor listed has no top margin.

 

here is my first attempt using GSAP to add some animation:

See the Pen GZBLVj by chrisk2020 (@chrisk2020) on CodePen

 

I'd like to know if the approach I'm using with multiple timelines is a good one? - it seems to be getting quite complicated and not particularly DRY, but that might just be my synatx?

 

I'm also not sure of the best method to calculate heights including padding, borders and margin and have had to rely on 'magic' hard coded numbers to compensate in the height calculations. This might be OK, but I'm also at a loss as to how to gracefully cope with the 0 marginTop on the first list item title - as in getting it all moving smoothly to the eye.

 

I've been trying to find the best way to get this feeling nice and solid and would really appreciate some pointers.

See the Pen NNomGz by chrisk2020 (@chrisk2020) on CodePen

Link to comment
Share on other sites

I've continued to work on the above problem and have something that more closely resembles what I'm after - 

See the Pen yOwBXJ by chrisk2020 (@chrisk2020) on CodePen

 

I'm still getting a 'jump' in certain places - I think due to the animation of the margin.

 

Am I missing something about animating the margin property? or have I misdiagnosed the cause of the jump?

 

Thanks in advance.

Link to comment
Share on other sites

Thanks for posting the demo and reporting your progress.

 

Unfortunately it is just too complex for us dig deep into to try to figure out exactly what is happening. With all the conditions, multiple timelines, and jQuery things going on its a lot to dissect with fresh eyes. The good news is that it seems like you are pretty close.

 

In order for us to best help we really need to focus on issues that are closely tied to the GSAP API. If you can create a super simple demo that shows just one use case that you are trying to solve it may help us in providing a solution. Something like : "click this button to remove 2 elements and tween to the new height". 

 

 

I would suggest studying this post and the examples. http://greensock.com/forums/topic/10637-animating-height-auto/

They deal with ways of tweening to and from heights that change based on size of content. I'm confident the same concepts can translate over to what you are doing.

  • Like 1
Link to comment
Share on other sites

Hi OSUblake - thanks for the excellent demos and clear explanations on the posts linked.

 

I've started to put something together based on the techniques in your demos:

 

See the Pen pyBGLv by chrisk2020 (@chrisk2020) on CodePen

 

I'm trying to use a callback to apply a tween to all the '.apartments' that are NOT filtered - ultimately to fade them out, but in the first instance to change their colour. It's not quite working as I expected - I'm guessing that it has something to do with the 'parent' tween toggling on the reverse, but the callback tween not being aware of that state? Would that be the case?

 

Is there a better way to toggleAnimations on selected elements that are NOT the target element(s) its self?

 

Edit:

I've made a bit more progress here: 

See the Pen aNxMKa?editors=0010 by chrisk2020 (@chrisk2020) on CodePen

I think my logic must be off somewhere though because the tweens are triggering on multiple clicks of the button. ie. the first filter click hides everything, then the second filter click filters seemingly pretty correctly - though if the correct filter is shown I'd like to disable the toggle.

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...