Design comparison
Solution retrospective
I'm pleased that I was able to complete the challenge to the design specifications while only using HTML and CSS.
What challenges did you encounter, and how did you overcome them?I looked into animating the opening and closing of the `````` components, but was unable to achieve the results that I wanted.
What specific areas of your project would you like help with?I would appreciate any suggestions for animating the `````` components or any other tips/suggestions to improve the quality of my code.
Community feedback
- @juliengDevPosted about 1 month ago
Hi @nvalline, Hope you are doing fine
Im going to try to anwser to the animation question you have.
This how i approach the problem myself :
-
I used CSS transitions for smooth animations, particularly on the
max-height
property. -
Instead of toggling a
hidden
attribute, I manipulated themax-height
of the panel:- For closed panels:
max-height: 0px
- For open panels:
max-height: panel.scrollHeight + "px"
- For closed panels:
-
I added a CSS transition on the
max-height
property in our stylesheet:.accordion-panel { transition: max-height 0.3s ease-out; overflow: hidden; }
-
In the JavaScript, I updated the
toggleAccordion
method to set the appropriatemax-height
:if (expand) { panel.style.maxHeight = panel.scrollHeight + "px"; } else { panel.style.maxHeight = "0px"; }
-
I also added a
visible
class to control opacity for a fade-in effect:.accordion-panel { opacity: 0; transition: max-height 0.3s ease-out, opacity 0.3s ease-out; } .accordion-panel.visible { opacity: 1; }
This solution provides a smooth animation when opening and closing accordion panels, addressing the challenge mentioned in the review. It combines CSS transitions with JavaScript manipulation of element properties to achieve the desired effect without relying on complex libraries or excessive code.
It might have another solution, but here is mine, hope it helps you to understand more the concept behind the effect.
Marked as helpful0 -
Please log in to post a comment
Log in with GitHubJoin our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord