【问题标题】:How to change image without closing a modal in html/css如何在不关闭 html/css 中的模式的情况下更改图像
【发布时间】:2015-11-30 12:41:06
【问题描述】:

每当我打开模态框时,它看起来都很好,但是当我单击数字“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>

【问题讨论】:

  • 寻求代码帮助的问题必须在问题本身中包含重现它所需的最短代码。尽管您提供了一个示例链接,但如果该链接失效,您的问题对于未来遇到相同问题的其他 SO 用户将毫无价值。

标签: html css popup modal-dialog popupwindow


【解决方案1】:

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

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

jQuery API stopPropagation

对于更多的 cmets,您应该考虑将您正在使用的 javascript 添加到您的帖子中。

【讨论】:

  • 对不起,我是新手,我该在哪里插入?
猜你喜欢
  • 2016-06-09
  • 1970-01-01
  • 1970-01-01
  • 2014-07-04
  • 2013-10-25
  • 2012-07-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多