Dropdown menus to open up near bottom of the page
This commit is contained in:
parent
a00851a8b2
commit
1936bcde37
|
@ -1,4 +1,4 @@
|
|||
// Hamburger menu script for mobile.
|
||||
// Bulma CSS fixes and features for nonshy.
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
|
||||
// Make all off-site hyperlinks open in a new tab.
|
||||
|
@ -84,6 +84,19 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||
|
||||
// Dropdown menus.
|
||||
(document.querySelectorAll(".dropdown") || []).forEach(node => {
|
||||
// If this dropdown is near the bottom of the page, make it open upwards.
|
||||
if (!node.classList.contains("is-up") && !node.classList.contains("is-right")) {
|
||||
let offsetTop = node.offsetTop,
|
||||
body = document.body,
|
||||
html = document.documentElement,
|
||||
pageHeight = Math.max(body.scrollHeight, body.offsetHeight,
|
||||
html.clientHeight, html.scrollHeight, html.offsetHeight,
|
||||
);
|
||||
if (pageHeight - offsetTop < 450) {
|
||||
node.classList.add("is-up");
|
||||
}
|
||||
}
|
||||
|
||||
const button = node.querySelector("button");
|
||||
button.addEventListener("click", (e) => {
|
||||
node.classList.toggle("is-active");
|
||||
|
|
Loading…
Reference in New Issue
Block a user