<style>
.panels {
display:flex
}
.panel {
flex: 1
justify-content: center
display: flex
flex-direction: column
}
.panel.open{
flex: 5
}
.panel > * {
flex: 1 0 auto
display: flex
justify-content: center
align-items: center
}
.panel > *:first-child { transform: translateY(-100%) }
.panel.open-active > *:first-child { transform: translateY(0) }
.panel > *:last-child { transform: translateY(100%) }
.panel.open-active > *:last-child { transform: translateY(0) }
</style>
<script>
const panels = document.querySelectorAll('.panel')
function toggleOpen(){
this.classList.toggle('open')
}
function toggleActive(e){
if(e.propertyName.includes('flex'){
this.classList.toggle('open-active)
}
}
panels.forEach((p)=> p.addEventListener('click', toggleOpen))
panels.forEach((p)=> p.addEventListener('transitioned', toggleActive))
</script>