2024-12-19 02:44:14 +00:00
|
|
|
const enlargeImg = document.querySelectorAll(".enlarge");
|
|
|
|
const body = document.querySelector("body");
|
|
|
|
const main = document.querySelector("main");
|
|
|
|
const nav = document.querySelector("nav");
|
|
|
|
const header = document.querySelector("header");
|
2024-12-19 04:32:38 +00:00
|
|
|
// script tag needs defer attribute as footer is included by php
|
|
|
|
// after script tag. defer makes sure the script is loaded after
|
|
|
|
// everything else on the page has loaded
|
|
|
|
const footer = document.querySelector("footer");
|
2024-12-19 20:36:50 +00:00
|
|
|
|
2024-12-19 02:44:14 +00:00
|
|
|
enlargeImg.forEach((img) => {
|
|
|
|
img.style.cursor = "pointer";
|
|
|
|
|
|
|
|
img.addEventListener("click", () => {
|
2024-12-19 04:32:38 +00:00
|
|
|
// make background for image
|
2024-12-19 02:44:14 +00:00
|
|
|
let div = document.createElement("div");
|
2024-12-19 20:36:50 +00:00
|
|
|
div.style.display = "flex";
|
|
|
|
div.style.flexDirection = "column";
|
|
|
|
div.style.alignItems = "center";
|
|
|
|
div.style.justifyContent = "center";
|
2024-12-19 02:44:14 +00:00
|
|
|
div.style.height = "100vh";
|
|
|
|
div.style.width = "auto";
|
|
|
|
div.style.backgroundColor = "#000000";
|
|
|
|
|
2024-12-19 20:36:50 +00:00
|
|
|
// image element
|
|
|
|
let image = document.createElement("img");
|
|
|
|
image.src = img.src;
|
|
|
|
image.style.height = "80%";
|
|
|
|
image.style.width = "auto";
|
|
|
|
div.append(image);
|
|
|
|
|
|
|
|
let paragraph = document.createElement("p");
|
|
|
|
paragraph.textContent = "Click anywhere on the image or the black background to close. You can also press the x key on your keyboard.";
|
|
|
|
paragraph.style.color = "#FFFFFF";
|
|
|
|
div.append(paragraph);
|
2024-12-19 04:32:38 +00:00
|
|
|
// hide current page contents
|
2024-12-19 02:44:14 +00:00
|
|
|
main.style.display = "none";
|
|
|
|
nav.style.display = "none";
|
2024-12-19 04:32:38 +00:00
|
|
|
footer.style.display = "none";
|
2024-12-19 02:44:14 +00:00
|
|
|
header.style.display = "none";
|
|
|
|
|
2024-12-19 04:32:38 +00:00
|
|
|
// remove display: grid from body and append div with enlarged image
|
2024-12-19 02:44:14 +00:00
|
|
|
body.style.display = "block";
|
|
|
|
body.append(div);
|
2024-12-19 20:36:50 +00:00
|
|
|
|
|
|
|
const removeDiv = () => {
|
2024-12-19 02:44:14 +00:00
|
|
|
div.remove();
|
|
|
|
body.style.display = "grid";
|
|
|
|
main.style.display = "block";
|
|
|
|
nav.style.display = "block";
|
|
|
|
header.style.display = "flex";
|
2024-12-19 20:36:50 +00:00
|
|
|
footer.style.display = "flex";
|
|
|
|
};
|
|
|
|
|
|
|
|
div.addEventListener("click", removeDiv);
|
|
|
|
|
|
|
|
body.addEventListener("keydown", (e) => {
|
|
|
|
if (e.key === "x") {
|
|
|
|
removeDiv();
|
|
|
|
}
|
|
|
|
});
|
2024-12-19 02:44:14 +00:00
|
|
|
});
|
|
|
|
});
|