Little effects on our web pages can make a lot of difference on the user experience of a website. When the state of an element is changed, it's pre...
For further actions, you may consider blocking this person and/or reporting abuse
Just one thing : it's best to transition using transform instead of height, max-height, width... for better browser performance
see csstriggers.com/
To expand on this:
When transitioning height, the DOM has to re-flow (or re-layout) all affected elements. This is computationally expensive considering transitions attempt to animate at 60fps. That's 60 recalculations per second!
With translate, you're only affecting the element's appearance. In other words, translation does not affect layout, as it's applied post-layout.
With that said, this also complicates things. In your example, using translate to animate the text will not re-calculate the button's position, so it's not as simple as animating translate as a drop-in replacement. I actually think your solution is great for most use-cases.
Thank you for this comment.
Thank you for pointing this out.
With max-height you should know the element computed height because if the content have a variable length 1500px may can’t be enough.
If you set a custom property to replace the max-height value, with js you can get the actual element height and change the max-height custom property runtime.
Anyway you should not transitioning height or max-height. Transforming a clip-path property may be more performant. Cheers.
Hey Great article.
Your solution for when you don't know the height will delay the transition if for example the max-height is transitioning from a higher value than the actual height there is no noticeable change until the max-height reaches the height of the element.
As of now I haven't discovered a better solution for when you don't know the height.
I'd like to point out a pitfall of the second method: if you have multiple elements that you need to collapse and their heights differs considerably, the animation will seem to "lag" for shorter elements because of their max-height property being much higher than their actual height.
I often use your proposed solution for quick collapses but the only solution if you want perfect collapses involves pure Javascript and Element.scrollHeight property
I'm glad you pointed this out
This is a very good post ! Thanks for this
Thank you, Sarah. Your information helped a lot! :)
Thank you, Sarah. Your information helped me a lot! :)