I want to show a customized dropdown inside a scroll-box (overflow-y: scroll). But the dropdown options is hidden at the bottom of the scroll-box. I also tried setting z-index to the dropdown-options and its parents, but still not working. How can I show the dropdown-options over the layer of the scroll-box and its surroundings?
function findAll_fakeDropdownBtn() {
return document.querySelectorAll('.nts-fakeDropdownBtn');
}
function findAll_fakeDropdownOptionsContainer() {
return document.querySelectorAll('.nts-fakeDropdownOptionsContainer');
}
window.onload = function () {
findAll_fakeDropdownBtn().forEach(function(fakeDropdownBtn) {
fakeDropdownBtn.addEventListener('click', function(event) {
var ddocId = fakeDropdownBtn.dataset.ddocId;
var fakeDropdownOptionsContainer = document.querySelector('#'+ddocId);
var isDisplaying = fakeDropdownOptionsContainer.classList.contains('nts-fakeDropdownOptionsContainer-displaying');
// Show/Hide the one target dropdown.
if (isDisplaying) {
fakeDropdownOptionsContainer.classList.remove('nts-fakeDropdownOptionsContainer-displaying');
} else {
fakeDropdownOptionsContainer.classList.add('nts-fakeDropdownOptionsContainer-displaying');
}
});
});
findAll_fakeDropdownOptionsContainer().forEach(function(fakeDropdownOptionsContainer) {
fakeDropdownOptionsContainer.querySelectorAll('.nts-dropdown-option').forEach(function(dropdownOptionElm) {
dropdownOptionElm.addEventListener('click', function(event) {
dropdownOptionElm.classList.toggle('nts-dropdown-option-selected');
});
});
});
}
.nts-fakeDropdownOptionsContainer-displaying {
display: block !important;
}
.nts-dropdown-option:hover {
background-color: orange !important;
}
.nts-dropdown-option-selected {
background-color: red !important;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body style="background-color: tan;">
<div>
<div style="margin-left: 50px; background-color: coral;">
<div style="height: 150px; overflow-y: scroll; width: 300px; background-color: papayawhip;">
<div><span>Some text..</span></div>
<div><span>Some text..</span></div>
<div><span>Some text..</span></div>
<div><span>Some text..</span></div>
<div style="position: relative;">
<span>Some text..</span>
<div id="elmId-fakeDropdownBtn-2"
class="nts-fakeDropdownBtn"
data-ddoc-id="elmId-fakeDropdownOptionsContainer-2"
style="background-color: green; width: 150px; height: 20px;">DropdownBtn</div>
<div id="elmId-fakeDropdownOptionsContainer-2"
class="is-ddconpart nts-fakeDropdownOptionsContainer"
style="position: absolute; background-color: lightseagreen; width: 100px; display: none;">
<div class="is-ddconpart nts-dropdown-option">Option-A</div>
<div class="is-ddconpart nts-dropdown-option">Option-B</div>
<div class="is-ddconpart nts-dropdown-option">Option-C</div>
<div class="is-ddconpart nts-dropdown-option">Option-D</div>
<div class="is-ddconpart nts-dropdown-option">Option-E</div>
</div>
</div>
<div><span>Some text..</span></div>
<div><span>Some text..</span></div>
<div><span>Some text..</span></div>
<div><span>Some text..</span></div>
<div><span>Some text..</span></div>
<div><span>Some text..</span></div>
</div>
</div>
</div>
</body>
</html>
