Dynamic dropdown menu placement based on the toggle location

This commit is contained in:
Sodbileg Gansukh
2023-11-13 19:29:41 +08:00
parent 946e063117
commit 78ff9df4ea
6 changed files with 13 additions and 6 deletions

View File

@@ -56,6 +56,13 @@ function dropdown() {
toggle.appendChild(wrapper);
nav.appendChild(toggle);
const toggleRect = toggle.getBoundingClientRect();
const documentCenter = window.innerWidth / 2;
if (toggleRect.left < documentCenter) {
wrapper.classList.add('is-left');
}
head.classList.add('is-dropdown-loaded');
window.addEventListener('click', function (e) {