Hi everyone. I can’t seem to make sense of why this exercise is failing me. The exercise is at:
Build a Lightbox Viewer: Build a Lightbox Viewer | freeCodeCamp.org
I keep getting a message that says:
Your lightbox element should cover the entire viewport.
However, the lightbox element is indeed covering the entire viewport. Here’s the code:
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="styles.css">
</head>
<body>
<header>
<h1>Art by Manu</h1>
</header>
<div class="gallery">
<img src="https://cdn.freecodecamp.org/curriculum/labs/stonehenge-thumbnail.jpg" class="gallery-item">
<img src="https://cdn.freecodecamp.org/curriculum/labs/storm-thumbnail.jpg" class="gallery-item">
<img src="https://cdn.freecodecamp.org/curriculum/labs/trees-thumbnail.jpg" class="gallery-item">
</div>
<div class="lightbox">
<button id="close-btn">×</button>
<img id="lightbox-image">
</div>
<script src="script.js"></script>
</body>
</html>
This is the CSS:
body {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: Muli, sans-serif;
font-size: 18px;
}
header {
text-align: center;
}
.gallery {
margin: auto;
width: 100%;
display: grid;
grid-template-columns: 1fr 1fr 1fr;
}
.gallery-item {
max-width: 100%;
height: 100%;
object-fit: cover;
cursor: pointer;
}
.lightbox {
display: none;
position: fixed;
width: 100vw;
height: 100vh;
top: 0;
left: 0;
background-color: #666;
flex-shrink: 0;
align-items: center;
justify-content: center;
overflow: hidden;
z-index: 1;
}
button {
position: fixed;
top: 0;
right: 0;
font-family: "Muli";
font-size: 20px;
}
#lightbox-image {
margin:auto;
width: 90vw;
}
And this is the Javascript:
const lightBox = document.querySelector(".lightbox");
const closeBtn = document.getElementById("close-btn");
const lightBoxImage = document.getElementById("lightbox-image");
const imageAtZero = "https://cdn.freecodecamp.org/curriculum/labs/stonehenge.jpg";
const imageAtOne = "https://cdn.freecodecamp.org/curriculum/labs/storm.jpg";
const imageAtTwo = "https://cdn.freecodecamp.org/curriculum/labs/trees.jpg";
const getBigPic = (index) => {
let url;
switch(index) {
case 0: url = imageAtZero;
case 1: url = imageAtOne;
case 2: url = imageAtTwo;
}
return url;
}
const zoomIn = (index) => {
lightBox.style.display = "flex";
let featuredPicUrl;
switch(index) {
case 0: featuredPicUrl = imageAtZero; break;
case 1: featuredPicUrl = imageAtOne; break;
case 2: featuredPicUrl = imageAtTwo; break;
}
lightBoxImage.setAttribute("src", featuredPicUrl);
}
const closeBox = () => {
lightBox.style.display = "none";
lightBoxImage.removeAttribute("src");
};
galleryItems[0].addEventListener('click', () => { zoomIn(0); });
galleryItems[1].addEventListener('click', () => { zoomIn(1); });
galleryItems[2].addEventListener('click', () => { zoomIn(2); });
closeBtn.addEventListener('click', () => { closeBox() });
lightBox.addEventListener('click', () => { closeBox() });
What am I missing?