You don’t need JavaScript to create a dropdown effect, you can accomplish the same thing using CSS transition
.
Example
<ul>
<li>
Parent
<ul>
<li>Child 1</li>
<li>Child 2</li>
<li>Child 3</li>
</ul>
</li>
</ul>
:root {
--border-size: 3px;
}
ul {
list-style: none;
margin: 0;
padding: 0;
display: inline-block;
}
ul > li {
display: inline-block;
position: relative;
width: 100px;
text-align: center;
padding: 5px;
border: var(--border-size) solid;
cursor: pointer;
}
li > ul {
position: absolute;
top: calc(100% + var(--border-size));
left: calc(var(--border-size) * -1);
transform: scale(1,0);
transform-origin: top;
transition: all ease-in 200ms 50ms;
}
li:hover > ul {
transform: scale(1,1);
}
ul > li li {
border-top: none;
}
Result
-
Parent
- Child 1
- Child 2
- Child 3