Design comparison
Solution retrospective
Been a while since I used javascript, so the script feels needlessly complex for something as simple as a click event.
Would love some tips on how to deal with javascript in this situation.
Had to configure the answers' class in the css to absolute and push them far away from the entire body so I could animate a transition instead of a sloppy display block reveal. If any alternatives to this solution, I would love to know.
Community feedback
- @NJVSPosted about 2 years ago
Hi Caleb, what I've done is initially set a
max-height: 0
to thep.answer
, you can't animate a transition if you just set max-height to auto, so i use javascript propertyscrollHeight
to get it's fully expanded height.//style.css .answer { max-height: 0; } //script.js button.addEventListener('click', function(){ const answer= target.closest('div.faq-container').querySelector('p.answer'); answer.style.maxHeight = `${answer.scrollHeight}px` }
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