问题与模态图像成为背景图像

时间:2018-04-26 15:30:28

标签: javascript html css

我对这一切都很陌生,所以如果已经有答案,我道歉。我的页面上的模态图像存在重大问题。出于某种原因,当模态图像被启动时,它最终会出现在网站的背景中,文本和其他内容最终会被置于顶部。

以下是查看的链接:http://demottdrapery.com/project/expirement/

以下是我目前对此页面的编码。

    <table class="dylan">
  <tr>
  <div class="goku">
    <td class="talks">
        <img id="myImg" src="http://demottdrapery.com/wp- 
   content/uploads/2017/12/MASTER-BED-1- 
   1.jpg"style="width:100%;height:auto;"class="visual">

          </td>
          </div>
          <div class="goku">
    <td class="talks">
        <img id="myImg" src="http://demottdrapery.com/wp- 
   content/uploads/2017/12/DINING-ROOM-1-1.jpg"style="width:100%; 
    height:auto;"class="visual">   
    </td>
    </div>
    <div id="myModal" class="modal">
    <img class="modal-content" id="img01">
    </div>
    </tr>
    </table>

      <script>
    // create references to the modal...
    var modal = document.getElementById('myModal');
    // to all images
     var images = document.getElementsByClassName('visual');
      // the image in the modal
     var modalImg = document.getElementById("img01");

     // Go through all of the images with our custom class
     for (var i = 0; i < images.length; i++) {
      var img = images[i];
      // and attach our click listener for this image.
      img.onclick = function (evt) {
    console.log(evt);
    modal.style.display = "block";
    modalImg.src = this.src;
    captionText.innerHTML = this.alt;
     }
    }

     // When the user clicks anywhere outside of the modal, close it
     window.onclick = function(event) {
       if (event.target == modal) {
           modal.style.display = "none";
       }
    }
    </script>

    <style>
        #myImg {
      cursor: pointer;
      transition: 0.3s;
    }
     .modal {
     display: none;
     /* Hidden by default */
     position: fixed ;
     /* Stay in place */
     z-index:100;
     /* Sit on top */
     padding-top: 100px;
      /* Location of the box */
      left: 0;
      top: 0;
      width: 100%;
     /* Full width */
     height: 100%;
     /* Full height */
     overflow: hidden;
     /* Enable scroll if needed */
     background-color: rgb(0, 0, 0);
     /* Fallback color */
     background-color: rgba(0, 0, 0, 0.9);
     /* Black w/ opacity */
    }

    .modal-content {
    margin: auto;
    display: block;
    width: 80%;
    max-width: 700px;
   }

       @keyframes zoom {
       from {
         transform: scale(0)
        }
         to {
          transform: scale(1)
       }
    }

       @media only screen and (max-width: 700px) {
      .modal-content {
      width: 100%;
     }
     .dylan{
        margin: 50px auto 0;
      width:100%;
      border-spacing:20px 0;   
     }
      .talks{
      position: relative;
      overflow: hidden;
            overflow-x: hidden;
            overflow-y: hidden;
        padding-top:45%;
    }
    .visual{
        position:absolute;
      top: 0;
      left:0;
      background-position: center center;
       background-size: cover;
      background-repeat: no-repeat;
    }
     .goku{
      position: relative;
      overflow: hidden;
      overflow-x: hidden;
      overflow-y: hidden;
  }
  }

1 个答案:

答案 0 :(得分:0)

应用于该父元素中的元素的任何z-index将仅应用于该父元素中的其他元素。父对象中的所有元素都将相应地堆叠,然后整个元素将被放置在其堆栈顺序指定的文本后面。

将模态div移到页面内容的其余部分之上。在此之后你可能需要重写你的js我不是很擅长JS。

<div id="myModal" class="modal">
  <img class="modal-content" id="img01">
</div>

<div data-vc-full-width="true" data-vc-full-width-init="true" data-vc-stretch-content="true" class="vc_row wpb_row vc_row-fluid vc_custom_1474396432392 vc_row-has-fill vc_row-o-equal-height vc_row-o-content-middle vc_row-flex" style="position: relative; left: -15px; box-sizing: border-box; width: 1116px;">

...

<table class="dylan">
  <tr>
    <div class="goku">
      <td class="talks">
        <img id="myImg" src="http://demottdrapery.com/wp-content/uploads/2017/12/MASTER-BED-1-1.jpg" style="width:100%;height:auto;"class="visual">
      </td>
    </div>
    <div class="goku">
      <td class="talks">
        <img id="myImg" src="http://demottdrapery.com/wp-content/uploads/2017/12/DINING-ROOM-1-1.jpg" style="width:100%; height:auto;"class="visual">   
      </td>
    </div>
  </tr>
</table>