Last active
October 8, 2020 13:22
-
-
Save BulatSa/d8b704ae85c90cde252b1f9211e42ae4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div className="parent"> | |
<h3 onClick={toggleView}>Утро</h3> | |
<div className="hidden-child"> | |
<p>Здравствуйте!</p> | |
</div> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
}; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.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