update height with request animation frame
updateHeight(isOpen) {
this.lastRAF && cancelAnimationFrame(this.lastRAF);
if (isOpen) {
this.lastRAF = requestAnimationFrame(() => {
// read:
const height =`${this.contentEl.scrollHeight}px`;
this.lastRAF = requestAnimationFrame(() => {
// write in a different frame:
this.containerEl.style.height = height;
this.lastRAF = null;
});
});
} else {
this.containerEl.style.height = '0px';
}
}