Jump to content
Search Community

gsap.getProperty height returning 'auto'

tpav test
Moderator Tag

Recommended Posts

I developed an animation in isolation and everything worked, now that I've combined it on another page with other page elements

 

gsap.getProperty('.chat1', 'height')

 

returns 'auto' whereas is retuned  a number before. chat1 has no set CSS height.

 

document.querySelector('.chat1').offsetHeight);

 

still returns a number.

 

I'm wracking my brain trying to figure out what's different. Comparing the element with Chrome dev tools, they seem to have identical properties.

 

gsap-element.png.c8ebc477a39c17a2b7810e4be596b596.png

Link to comment
Share on other sites

There may be something to that! I'll look into it.  Here's the demo. Moving it to CodePen surfaced another variable. Seems GSAP returns the height if the div's content, while javascript, and what I want is the height plus padding. Trying to center the left icon on the varying heights of the right div. 

 

See the Pen XWqoayx by tpavell (@tpavell) on CodePen

 

Can't explain why it all works here on my original dev page

Link to comment
Share on other sites

There are two problems with your demo: 

  1. You're calculating those values at completely different times. Technically the height isn't changing so it doesn't really make a difference here, but I wanted to point out that you're running the gsap.getProperty() stuff immediately (on the very first tick) whereas you've got the "js" one calculating after 4 seconds. Again, it doesn't make a difference in this case...I just wanted to point it out. 
  2. The REAL problem is just a misunderstanding about how height is calculated. The computed CSS "height" property is affected by the box-sizing property. The offsetHeight is different in that regard. Just set box-sizing: border-box and you'll see that the values match (well, some browsers may actually add some decimals to one and not the other but for all practical purposes they match). 

Here's the proof: 

See the Pen jOxXYNr?editors=0010 by GreenSock (@GreenSock) on CodePen

 

I hope that helps. 

Link to comment
Share on other sites

SOLVED: Even though the animation parent was set to block before the animation began, the animated elements parent was initially rendered with display:none Reworking the page to avoid using display:none solved the issue. Thank you Rogrigo and Jack for pointing me in the right direction.

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