我有一个固定的侧面导航菜单,其中包含一个Dropdown可以展开/折叠其他行的菜单项。
如果Dropdown在容器底部展开时,如果不手动向下滚动,我将看不到菜单项:

如何使它Dropdown在该位置展开并自动向下滚动(如果需要)足以显示所有子项?:


var dropdown = document.getElementsByClassName("dropdown-btn");
var i;
for (i = 0; i < dropdown.length; i++) {
dropdown[i].addEventListener("click", function() {
this.classList.toggle("active");
var dropdownContent = this.nextElementSibling;
if (dropdownContent.style.display === "block") {
dropdownContent.style.display = "none";
} else {
dropdownContent.style.display = "block";
}
});
}
<div class="sidenav">
<a href="#about">About</a>
<a href="#services">Services</a>
<a href="#clients">Clients</a>
<a href="#clients">MenuItem</a>
<a href="#clients">MenuItem6</a>
<button class="dropdown-btn">Dropdown
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-container">
<a href="#">Link 1</a>
<a href="#">Link 2</a>
<a href="#">Link 3</a>
</div>
<a href="#contact">Contact</a>
<a href="#contact">Search</a>
<a href="#clients">MenuItem2</a>
<a href="#clients">MenuItem9</a>
</div>
<div class="main">
<h2>Sidebar Dropdown</h2>
<p>Click on the dropdown button to open the dropdown menu inside the side navigation.</p>
<p>This sidebar is of full height (100%) and always shown.</p>
<p>Some random text..</p>
</div>
跃然一笑
萧十郎
随时随地看视频慕课网APP
相关分类