Tell us what’s happening:
my lightbox related tests - 9,10,11,12,13,14 & 16 are failing. Even though these settings are already mentioned. And also on my local PC everything seems to be working.
But they are not running on the FCC sandbox.
Please help.
Your code so far
<!-- file: index.html -->
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Lightbox Viewer</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div class="gallery">
<div class="gallery-item-wrapper">
<img
src="https://cdn.freecodecamp.org/curriculum/labs/stonehenge-thumbnail.jpg"
alt=""
class="gallery-item"
/>
</div>
<div class="gallery-item-wrapper">
<img
src="https://cdn.freecodecamp.org/curriculum/labs/storm-thumbnail.jpg"
alt=""
class="gallery-item"
/>
</div>
<div class="gallery-item-wrapper">
<img
src="https://cdn.freecodecamp.org/curriculum/labs/trees-thumbnail.jpg"
alt=""
class="gallery-item"
/>
</div>
</div>
<div class="lightbox" style="display: none">
<button id="close-btn">×</button>
<div class="lightbox-image-wrapper">
<img src="#" alt="" id="lightbox-image" />
</div>
</div>
<script src="script.js"></script>
</body>
</html>
/* file: styles.css */
/* CSS */
*,
*::before,
*::after {
box-sizing: border-box;
margin: 0;
padding: 0;
}
html,
body {
height: 100vh;
width: 100vw;
position: realtive;
display: flex;
align-items: center;
justify-content: center;
}
.gallery {
display: flex;
flex-direction: row;
gap: 10px;
max-width: fit-content;
align-items: center;
justify-content: center;
}
.gallery-item-wrapper {
width: 25vw;
height: 40vh;
overflow: hidden;
border: 2px black solid;
transition: transform 0.2s ease-in-out;
}
.gallery-item {
width: 100%;
height: 100%;
display: block;
margin: 0;
padding: 0;
object-fit: cover;
object-position: center;
transition: transform 0.4s ease-in-out;
}
.gallery-item-wrapper:hover {
transform: scale(1.1);
}
.gallery-item:hover {
transform: scale(1.2);
}
.gallery-item-wrapper:active {
opacity: 90%;
}
.lightbox {
position: fixed;
left: 0;
top: 0;
width: 100vw;
height: 100vh;
background: rgba(235, 4, 4, 0.6);
/* display: flex; */
align-items: center;
justify-content: center;
}
#close-btn {
position: absolute;
right: 0;
top: 0;
font-size: 4rem;
font-weight: bold;
color: red;
border: none;
background-color: transparent;
cursor: pointer;
}
.lightbox-image-wrapper {
width: 80%;
height: 80%;
overflow: hidden;
border: 2px black solid;
}
#lightbox-image {
width: 100%;
height: 100%;
object-fit: cover;
}
/* file: script.js */
const fullSizeImages = {
"https://cdn.freecodecamp.org/curriculum/labs/stonehenge-thumbnail.jpg":
"https://cdn.freecodecamp.org/curriculum/labs/stonehenge.jpg",
"https://cdn.freecodecamp.org/curriculum/labs/storm-thumbnail.jpg":
"https://cdn.freecodecamp.org/curriculum/labs/storm.jpg",
"https://cdn.freecodecamp.org/curriculum/labs/trees-thumbnail.jpg":
"https://cdn.freecodecamp.org/curriculum/labs/trees.jpg",
};
const galleryItem = document.querySelectorAll(".gallery-item");
const lightbox = document.querySelector(".lightbox");
const lightboxImage = lightbox.querySelector("#lightbox-image");
const closeBtn = lightbox.querySelector("#close-btn");
galleryItem.forEach((thumbnail) => {
thumbnail.addEventListener("click", (e) => {
showLightbox(e.target.src);
e.stopPropagation();
});
});
closeBtn.addEventListener("click", (e) => {
dismissLightbox();
e.stopPropagation();
});
lightbox.addEventListener("click", (e) => {
dismissLightBox();
e.stopPropagation();
});
lightboxImage.addEventListener("click", (e) => {
e.stopPropagation();
});
function dismissLightBox() {
lightboxImage.src = "#";
lightbox.style.display = "none";
}
function showLightbox(source) {
lightbox.style.display = "none";
lightboxImage.onload = () => {
lightbox.style.display = "flex";
};
lightboxImage.onerror = () => {
console.log("Failed to load image, network error?");
};
lightboxImage.src = fullSizeImages[source];
}
Your browser information:
User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:147.0) Gecko/20100101 Firefox/147.0
Challenge Information:
Build a Lightbox Viewer - Build a Lightbox Viewer