I'm experimenting with a design pattern using .expands
to toggle .hidden
child classes for .expanded
auto-sized flex box elements.
Something like:
const expandClick = e => {
e.currentTarget.querySelectorAll('.expanded').forEach(child => {
child.classList.toggle('hidden')
})
}
document.querySelectorAll('.expands').forEach(expandable => {
expandable.addEventListener('click', expandClick)
})
https://jsfiddle.net/vpc8khq8/
When my inner content loses the display: none
attribute, I would like the height to ease out with a slight bounce, but I'm not quite sure how to pull that off with a vanilla CSS transition or a pinch of JS.
I came across this post: How can I transition height: 0; to height: auto; using CSS?
But many of the answers seem more like hacks with odd side effects and excess js / css than simple, lightweight solutions.
This does the trick with jQuery: https://jsfiddle.net/cm7a9jr7/
const expandClick = e => {
$(e.currentTarget).children('.expanded').each(function() {
$(this).slideToggle('slow', 'swing', function() {
$(this).toggleClass('hidden')
})
})
}
$(() => $('.expands').on('click', expandClick))
But, I'd like to use something leaner. Are the any recommended libraries or simple ways to pull this off in CSS?