Jump to content
Search Community

Trying to prevent jumping after animating height

jschins 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 will add a codepen later if needed but want to get the description posted first to see if this is common and an issue that might be solved without one.  I have a hidden element and am animating height and opacity on click of an expand/collapse button.  After the animation is complete I set the height of the element to auto in order to allow the container to grow / shrink if the user deletes/edits/adds contents in the element that was hidden.  

 

I'm setting a height cache on the element and check for that before computing the height on click so if the user abuses the button and clicks rapidly it won't jump.

 

The issue I experienced with the latest attempt was a pause after the height was animated and then a jump in height after I set the height to auto.  What is occurring is one of the child elements of the element I am animating the height of has paddingBottom and that is not being rendered when I get the height of the container and animate the height.  After I set the height of the parent to auto then it the padding is rendered and the height of the parent container jumps.  I had been setting the height to auto after the opacity was done animating which made it jump but after changing that call to immediately after finishing the height it is much better. The lingering issue is if the user abuses the expand collapse button by rapid pressing it jumps unlike the other elements I expand / collapse.  Any ideas / help is appreciated, thanks!

Link to comment
Share on other sites

Here is where I am in the debugging process.  I'm not sure if it will help but I can see what's going on and maybe there is an existing widely used solution.  I wrote that the inner element has paddingBottom in my initial post but that is incorrect, it has marginBottom.  On my test case I am getting a height of 132 if I do window.getComputedStyle(e).height or the e.parentNode.offsetHeight routine you supplied or $(e).outerHeight(true).  If I go directly to the child element and use the $(e).outerHeight(true) I get 156.  I don't want hardcode that or anything so I'm not sure what the best course of action here is.  I'm adding a screenshot of the dev console to illustrate the operations, hopefully it is clear enough.  Thanks for any suggestions.

Screen Shot 2018-09-25 at 12.43.02 PM.png

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