Lightbox Issue With Image

Hello, everyone!

I am currently attempting to implement a lightbox to my Pokedex project. Basically, whenever I click on one of the Pokemon images, I want to be able to have the lightbox popup, and display a caption below, that would include what type of pokemon it is, respectively (water, grass, fire, etc.)

When I click the image, the lightbox is showing up, however it does not display the image - just a black screen. Included below will be the following:

  • a screenshot of a hover over a pokemon
  • what is displayed after the image is clicked
    -& all accompanying code (JS, HTML, CSS)


HTML:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Dans' Dex</title>
    <link rel="stylesheet" type="text/css" href="styles.css" />
    
    <script src="logic.js"></script>

</head>
<body>



<div class="heading">
    <h1 class="title">
        Dans' Dex
    </h1>

</div>

<div class="names">

    <h3>
001 Bulbasaur
    </h3>

    <h3>
002 Ivysaur   
    </h3>

    <h3>
    003 Venusaur   
    </h3>

    
    
</div>


<div class="images">

    <img src="images/please.png" onclick="openModal();currentSlide(1)" class="hover-shadow cursor">
    <img src="images/ivyyy.png" onclick="openModal();currentSlide(2)" class="hover-shadow cursor">
    <img src="images/vennn.png" onclick="openModal();currentSlide(3)" class="hover-shadow cursor">

</div>


<div class="names">
<h3>004 Charmander</h3>
<h3>005 Charmeleon </h3>
<h3>006 Charizard</h3>
</div>

<div class="images">

<img src="images/charm.png" onclick="openModal();currentSlide(4)" class="hover-shadow">
<img src="images/charmeleon.png"  class="hover-shadow" onclick="openModal();currentSlide(5)">
<img src="images/charizard.png"   class="hover-shadow" onclick="openModal();currentSlide(6)">

</div>

<div id="myModal" class="modal">
    <span class="close cursor" onclick="closeModal()">&times;</span>
    <div class="modal-content">

        <div class="mySlides">
            <div class="numbertext">1 / 4</div>
            <img src="images/please.png" style="width:100%">
          </div>
          <div class="mySlides">
            <div class="numbertext">2 / 4</div>
            <img src="images/ivyyy.png" style="width:100%">
          </div>
          <div class="mySlides">
            <div class="numbertext">3 / 4</div>
            <img src="images/vennn.png" style="width:100%">
          </div>
          <div class="mySlides">
            <div class="numbertext">4 / 4</div>
            <img src="images/charm.png" style="width:100%">
          </div>
          <a class="prev" onclick="plusSlides(-1)">&#10094;</a>
          <a class="next" onclick="plusSlides(1)">&#10095;</a>
          <div class="caption-container">
            <p id="caption">Test Test</p>
          </div>
          <div class="column">
            <img class="demo" src="images/please.png" onclick="currentSlide(1)" alt="Bulbasaur">
          </div>
          <div class="column">
            <img class="demo" src="images/ivyyy.png" onclick="currentSlide(2)" alt="Ivysaur">
          </div>
          <div class="column">
            <img class="demo" src="images/vennn.png" onclick="currentSlide(3)" alt="Venusaur">
          </div>
          <div class="column">
            <img class="demo" src="images/charm.png" onclick="currentSlide(4)" alt="Charmander">
          </div>
        </div>
      </div>


</div>

</body>
</html>

CSS:

.heading{
    display:flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    background: #3c5aa6;
    
}

.heading .title{
font-family:cursive;    color: white;
}

.names{
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-evenly;
    background:whitesmoke;
    font-family:'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    opacity: 75%;
}


.images{
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-evenly;
    background:#3c5aa6;
   


}

.uno{
height:50%;
width:50%
}


.row > .column {
    padding: 0 8px;
  }
  
  .row:after {
    content: "";
    display: table;
    clear: both;}

    .column {
        float: left;
        width: 25%;
      }
      .modal {
        display: none;
        position: fixed;
        z-index: 1;
        padding-top: 100px;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;
        overflow: auto;
        background-color: black;
      }

      .modal-content {
        position: relative;
        background-color: #fefefe;
        margin: auto;
        padding: 0;
        width: 90%;
        max-width: 1200px;
      }

      .close {
        color: white;
        position: absolute;
        top: 10px;
        right: 25px;
        font-size: 35px;
        font-weight: bold;
      }

      .close:hover,
.close:focus {
  color: #999;
  text-decoration: none;
  cursor: pointer;
}

.mySlides {
    display: none;
  }

  .prev,
.next {
  cursor: pointer;
  position: absolute;
  top: 50%;
  width: auto;
  padding: 16px;
  margin-top: -50px;
  color: white;
  font-weight: bold;
  font-size: 20px;
  transition: 0.6s ease;
  border-radius: 0 3px 3px 0;
  user-select: none;
  -webkit-user-select: none;
}

.next {
    right: 0;
    border-radius: 3px 0 0 3px;
  }

  .prev:hover,
.next:hover {
  background-color: rgba(0, 0, 0, 0.8);
}

.numbertext {
    color: #f2f2f2;
    font-size: 12px;
    padding: 8px 12px;
    position: absolute;
    top: 0;
  }

  .caption-container {
    text-align: center;
    background-color: black;
    padding: 2px 16px;
    color: white;
  }

  img.demo {
    opacity: 0.6;
  }
  
  .active,
.demo:hover {
  opacity: 1;
}


.hover-shadow:hover {
    box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
  }

JS:

function openModal() {
  document.getElementById("myModal").style.display = "block"
}

function closeModal() {
  document.getElementById("myModal").style.display = "none"
}

var slideIndex = 1;
showSlides(slideIndex);

function plusSlides(n) {
  showSlides(slideIndex += n)
}

function currentSlide(n) {
  showSlides(slideIndex = n)
}



function showSlides(n) {

function showSlides(n) {

    var i;
    var slides = document.getElementsByClassName("mySlides");
    var dots = document.getElementsByClassName("demo");
    var captionText = document.getElementById("caption");
    if (n > slides.length) {slideIndex = 1}
    if (n < 1) {slideIndex = slides.length}
    for (i = 0; i < slides.length; i++) {
        slides[i].style.display = "none"
    }
    for (i = 0; i < dots.length; i++) {
        dots[i].className = dots[i].className.replace(" active", "")
    }
    slides[(slideIndex-1)].style.display = "block";
    dots[slideIndex-1].className += " active";
    captionText.innerHTML = dots[slideIndex-1].alt;
    
    
}

}


Any help or tips are greatly appreciated.

  • is this what is responsible for your “modal” background color?!
  • where is that “image” bit code?

it will be much easier if you put it up in a “codepen/repl/others like it” and share that link instead

happy learning :slight_smile:

You have an extra closing div tag that is closing the first .mySlides div in the wrong place. I would highly suggest you install the Prettier VS Code extension and format your code. Or use whatever code formatter you have available to you wherever it is you are running the code.

You have showSlides defined twice, one inside the other. Calling showSlides will just run the nested function creation not invoke the nested function.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.