Skip to content

Instantly share code, notes, and snippets.

@BulatSa
Last active October 8, 2020 13:22
Show Gist options
  • Save BulatSa/d8b704ae85c90cde252b1f9211e42ae4 to your computer and use it in GitHub Desktop.
Save BulatSa/d8b704ae85c90cde252b1f9211e42ae4 to your computer and use it in GitHub Desktop.
<div className="parent">
<h3 onClick={toggleView}>Утро</h3>
<div className="hidden-child">
<p>Здравствуйте!</p>
</div>
</div>
const toggleView = (event) => {
const parent = event.target.parentElement;
const el = parent.querySelector(".hidden-child");
el.style.height = el.scrollHeight + "px";
//el.scrollHeight = el.scrollHeight;
parent.classList.toggle("open");
el.style.height = parent.classList.contains("open")
? el.scrollHeight + "px"
: 0;
};
.parent {
&.open {
.hidden-child {
height: auto;
}
}
}
.hidden-child {
height: 0px;
overflow: hidden;
transition: height 0.6s ease;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment