mobile
This commit is contained in:
@@ -1,24 +1,24 @@
|
|||||||
document.getElementById("open-fin-modal").addEventListener("click", function() {
|
document.getElementById("open-fin-modal").addEventListener("click", function() {
|
||||||
document.getElementById("fin-modal").style.visibility = "visible";
|
document.getElementById("fin-modal").style.visibility = "visible";
|
||||||
document.body.classList.add("modal-open");
|
if (window.lockBodyScroll) window.lockBodyScroll();
|
||||||
});
|
});
|
||||||
|
|
||||||
document.querySelectorAll(".close-fin-modal").forEach(function(button) {
|
document.querySelectorAll(".close-fin-modal").forEach(function(button) {
|
||||||
button.addEventListener("click", function() {
|
button.addEventListener("click", function() {
|
||||||
document.getElementById("fin-modal").style.visibility = "hidden";
|
document.getElementById("fin-modal").style.visibility = "hidden";
|
||||||
document.body.classList.remove("modal-open");
|
if (window.unlockBodyScroll) window.unlockBodyScroll();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
document.getElementById("open-game-modal").addEventListener("click", function() {
|
document.getElementById("open-game-modal").addEventListener("click", function() {
|
||||||
document.getElementById("game-modal").style.visibility = "visible";
|
document.getElementById("game-modal").style.visibility = "visible";
|
||||||
document.body.classList.add("modal-open");
|
if (window.lockBodyScroll) window.lockBodyScroll();
|
||||||
});
|
});
|
||||||
|
|
||||||
document.querySelectorAll(".close-game-modal").forEach(function(button) {
|
document.querySelectorAll(".close-game-modal").forEach(function(button) {
|
||||||
button.addEventListener("click", function() {
|
button.addEventListener("click", function() {
|
||||||
document.getElementById("game-modal").style.visibility = "hidden";
|
document.getElementById("game-modal").style.visibility = "hidden";
|
||||||
document.body.classList.remove("modal-open");
|
if (window.unlockBodyScroll) window.unlockBodyScroll();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,41 @@ const footerHtml = `
|
|||||||
</footer>
|
</footer>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
// Scroll lock helper
|
||||||
|
(function() {
|
||||||
|
let _locked = false;
|
||||||
|
let _scrollY = 0;
|
||||||
|
|
||||||
|
function lockBodyScroll() {
|
||||||
|
if (_locked) return;
|
||||||
|
_scrollY = window.scrollY || window.pageYOffset || 0;
|
||||||
|
document.body.style.position = "fixed";
|
||||||
|
document.body.style.top = `-${_scrollY}px`;
|
||||||
|
document.body.style.left = "0";
|
||||||
|
document.body.style.right = "0";
|
||||||
|
document.body.style.width = "100%";
|
||||||
|
document.documentElement.classList.add("modal-open");
|
||||||
|
document.body.classList.add("modal-open");
|
||||||
|
_locked = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function unlockBodyScroll() {
|
||||||
|
if (!_locked) return;
|
||||||
|
document.body.style.position = "";
|
||||||
|
document.body.style.top = "";
|
||||||
|
document.body.style.left = "";
|
||||||
|
document.body.style.right = "";
|
||||||
|
document.body.style.width = "";
|
||||||
|
document.documentElement.classList.remove("modal-open");
|
||||||
|
document.body.classList.remove("modal-open");
|
||||||
|
window.scrollTo(0, _scrollY);
|
||||||
|
_locked = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
window.lockBodyScroll = lockBodyScroll;
|
||||||
|
window.unlockBodyScroll = unlockBodyScroll;
|
||||||
|
})();
|
||||||
|
|
||||||
function getCurrentTheme() {
|
function getCurrentTheme() {
|
||||||
return document.documentElement.getAttribute("data-theme") === "dark" ? "dark" : "light";
|
return document.documentElement.getAttribute("data-theme") === "dark" ? "dark" : "light";
|
||||||
}
|
}
|
||||||
@@ -102,17 +137,19 @@ document.addEventListener("DOMContentLoaded", function() {
|
|||||||
`;
|
`;
|
||||||
document.body.insertAdjacentHTML("beforeend", modalHtml);
|
document.body.insertAdjacentHTML("beforeend", modalHtml);
|
||||||
const modal = document.getElementById("image-modal");
|
const modal = document.getElementById("image-modal");
|
||||||
modal.style.visibility = 'visible';
|
modal.style.visibility = "visible";
|
||||||
document.body.classList.add("modal-open");
|
if (window.lockBodyScroll) window.lockBodyScroll();
|
||||||
|
|
||||||
modal.querySelector(".close").addEventListener("click", () => {
|
const closeBtn = modal.querySelector(".close");
|
||||||
modal.remove();
|
if (closeBtn) {
|
||||||
document.body.classList.remove("modal-open");
|
closeBtn.addEventListener("click", () => {
|
||||||
});
|
modal.remove();
|
||||||
|
if (window.unlockBodyScroll) window.unlockBodyScroll();
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function toggleTheme() {
|
function toggleTheme() {
|
||||||
const current = getCurrentTheme();
|
const current = getCurrentTheme();
|
||||||
const next = current === "dark" ? "light" : "dark";
|
const next = current === "dark" ? "light" : "dark";
|
||||||
|
|||||||
@@ -412,9 +412,11 @@ nav {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Prevent background scrolling while a modal is open */
|
/* Prevent background scrolling while a modal is open */
|
||||||
|
html.modal-open,
|
||||||
body.modal-open {
|
body.modal-open {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
touch-action: none;
|
touch-action: none;
|
||||||
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.close {
|
.close {
|
||||||
|
|||||||
Reference in New Issue
Block a user