const items = document.querySelectorAll(".item");
items.forEach(item => {
const hiddenText = item.querySelector(".item__hidden_text");
item.addEventListener("mouseenter", () => {
hiddenText.animate([
{height: 0},
{height: `${hiddenText.scrollHeight}px`}
], {
fill: "forwards",
duration: 300,
});
});
item.addEventListener("mouseleave", () => {
hiddenText.animate([
{height: `${hiddenText.scrollHeight}px`},
{height: 0}
], {
fill: "forwards",
duration: 300,
});
});
});
<div classname="wrapper">
<div classname="card"/>
<p classname="hidden-text">Hidden text</p>
</div>
.hidden-text{
opacity: 0;
}
.wrapper:hover{
transition: 0.2 ease;
.card{
transform: scale(1.2);
}
.hidden-text{
opacity: 1;
}
}