如何更改图像而不关闭html / css中的模态

时间:2015-11-30 12:41:07

标签: html css popup modal-dialog popupwindow

每当我打开模态时它看起来都很好,但是当我点击数字“2”,这是模态内画廊中的第二张照片时,它会关闭。如何在不关闭模态的情况下选择2(或任何其他数字)?

这是我的代码:

/* SLIDER CSS */
#images {
  width: 400px;
  height: 250px;
  overflow: hidden;
  position: relative;
  margin: 20px auto;
}

#images img {
  width: 400px;
  height: 250px;
  position: absolute;
  top: 0;
  left: -400px;
  z-index: 1;
  opacity: 0;
  transition: all linear 500ms;
  -o-transition: all linear 500ms;
  -moz-transition: all linear 500ms;
  -webkit-transition: all linear 500ms;
}

#images img:target {
  left: 0;
  z-index: 9;
  opacity: 1;
}

#images img:first-child {
  left: 0;
}

#slider a {
  text-decoration: none;
  background: #E3F1FA;
  border: 1px solid #C6E4F2;
  padding: 4px 6px;
  color: #222;
}

#slider a:hover {
  background: #C6E4F2;
}


/* MODAL CSS */
.modalDialog {
  position: fixed;
  font-family: Arial, Helvetica, sans-serif;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: rgba(0,0,0,0.8);
  z-index: 99999;
  opacity:0;
  -webkit-transition: opacity 400ms ease-in;
  -moz-transition: opacity 400ms ease-in;
  transition: opacity 400ms ease-in;
  pointer-events: none;
}

.modalDialog:target {
  opacity:1;
  pointer-events: auto;
}

.modalDialog > div {
  width: 400px;
  position: relative;
  margin: 10% auto;
  padding: 5px 20px 13px 20px;
  border-radius: 10px;
  background: #fff;
  background: -moz-linear-gradient(#fff, #999);
  background: -webkit-linear-gradient(#fff, #999);
  background: -o-linear-gradient(#fff, #999);
}

.close {
  background: #606061;
  color: #FFFFFF;
  line-height: 25px;
  position: absolute;
  right: -12px;
  text-align: center;
  top: -10px;
  width: 24px;
  text-decoration: none;
  font-weight: bold;
  -webkit-border-radius: 12px;
  -moz-border-radius: 12px;
  border-radius: 12px;
  -moz-box-shadow: 1px 1px 3px #000;
  -webkit-box-shadow: 1px 1px 3px #000;
  box-shadow: 1px 1px 3px #000;
}

.close:hover { 
  background: #00d9ff; 
}
<a href="#openJunior" ="">See more</a>

<div id="openJunior" class="modalDialog">
  <div>
    <a href="#close" title="Close" class="close">X</a>
    <div id="images">
      <img id="image1" src="http://lorempixel.com/400/250/people" />
      <img id="image2" src="http://lorempixel.com/400/250/sports" />
      <img id="image3" src="http://lorempixel.com/400/250/nature" />
      <img id="image4" src="http://lorempixel.com/400/250/abstract" />
      <img id="image5" src="http://lorempixel.com/400/250/animals" />
    </div>
    <div id="slider">
      <a href="#image1">1</a>
      <a href="#image2">2</a>
      <a href="#image3">3</a>
      <a href="#image4">4</a>
      <a href="#image5">5</a>
    </div>
  </div>
</div>

1 个答案:

答案 0 :(得分:0)

您可以尝试使用event.stopPropagation,例如:

$('.modalDialog').on('click', function(event){
      event.stopPropagation();
});

jQuery API stopPropagation

如需进一步评论,请考虑将您正在使用的javascript添加到帖子中。