I want the height to expand smoothly, but 95% of the time, the transition doesn't happen. Is this because the classList.toggle creates a new class string, and therefore the transition is lost? Either way, how do I resolve this? I must use vanilla JS for this.
document.querySelectorAll('.toggleMe').forEach(function (query) {
query.onclick = function (e) {
e.target.classList.toggle('open');
}
});
.toggleMe {
background: #e3e3e3;
max-height: 1.3rem;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
width: 100%;
transition: all ease 2s;
-moz-transition: all ease 2s; /* Firefox 4 */
-webkit-transition: all ease 2s; /* Safari and Chrome */
-o-transition: all ease 2s; /* Opera */
-ms-transition: all ease 2s; /* Explorer 10 */
}
.toggleMe.open {
max-height: 999px;
white-space: normal;
}
<div class="toggleMe">I am a really long sentence that wants to stay hidden on load, but when clicked will expand for all to see. But 95% of the time, the transition doesn't happen. Is this because the classList.toggle creates a new class string, and therefore the transition is lost?</div>