I'm trying to animate an elements height using css. The way I'm doing it is, I added a touch event to an element. The function adds a className
to the element that's supposed to hide, i.e. get a height of 0.
The problem is, when the element gets clicked, the div
that's supposed get a height of 0 pauses a second then gets the desired height. It seems like the longer the animation duration is, the long it waits before it animates.
Here's the relevant code:
transition: max-height 2s ease-in-out;
var heading = document.getElementById('heading'),
body = document.getElementById('body');
heading.addEventListener('click', hide);
body.addEventListener('transitionend', hideCallback);
function hide() {
body.className = 'hide';
}
function hideCallback(e) {
console.log(e.propertyName);
}
#wrapper {
margin: auto;
background-color: blue;
width: 470px;
text-align: center;
overflow: hidden;
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.19), 0 6px 6px rgba(0, 0, 0, 0.17);
max-height: 400px;
max-width: 600px;
padding: 0;
}
#buttonContainer {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: center;
align-content: center;
flex-direction: column;
margin: auto;
width: 100px;
height: 100px;
color: white;
}
#buttonIcon {
width: 36px;
height: 36px;
line-height: 36px;
font-size: 35px;
font-weight: bold;
display: inline-block;
}
#buttonLabel {
font-size: 20px;
}
#content {
width: 100%;
height: 100%;
text-align: left;
transform: translateY(0px);
}
#heading {
color: white;
text-align: right;
margin: 10px;
font-size: 17px;
}
#body {
color: #000;
color: rgba(0, 0, 0, 0.87);
background-color: #FFF;
width: 100%;
max-height: 500px;
padding: 10px 0;
box-sizing: border-box;
}
#body.hide {
transition: max-height 2s ease-in-out;
max-height: 0;
}
#innerBody {
height: 200px;
background-color: orange;
}
<div id="wrapper">
<div id="buttonContainer"><span id="buttonIcon">My</span><span id="buttonLabel">self</span>
</div>
<div id="content">
<div id="heading">Press Me</div>
<div id="body">
<div id="innerBody"></div>
</div>
</div>
</div>