【问题标题】:2 buttons side by side under my enlarged image我的放大图像下方并排有 2 个按钮
【发布时间】:2018-11-14 14:27:39
【问题描述】:

当您单击放大图像时,我想在图像底部创建 2 个按钮。到目前为止,我的图像可以点击放大,但我很难在放大图像的底部找到 2 个按钮。如果有人可以提供帮助,那就太好了!

我还尝试将单击按钮设置为另一个弹出表单。他们可以在哪里订购或查询该特定产品。请帮帮我,真的很赶时间。谢谢

这是我正在使用的代码:

// Get the modal
var modal = document.getElementById('myModal');

// Get the image and insert it inside the modal - use its "alt" text as a caption
var img = document.getElementById('myImg');
var modalImg = document.getElementById("img01");
var captionText = document.getElementById("caption");
img.onclick = function(){
    modal.style.display = "block";
    modalImg.src = this.src;
    captionText.innerHTML = this.alt;
}

// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];

// When the user clicks on <span> (x), close the modal
span.onclick = function() { 
    modal.style.display = "none";
}
/* Style the Image Used to Trigger the Modal */
#myImg {
    border-radius: 5px;
    cursor: pointer;
    transition: 0.3s;
}

#myImg:hover {opacity: 0.7;}

/* The Modal (background) */
.modal {
    display: none; /* Hidden by default */
    position: fixed; /* Stay in place */
    z-index: 1; /* Sit on top */
    padding-top: 100px; /* Location of the box */
    left: 0;
    top: 0;
    width: 100%; /* Full width */
    height: 100%; /* Full height */
    overflow: auto; /* Enable scroll if needed */
    background-color: transparent; /* Fallback color */
    background-color: transparent; /* Black w/ opacity */
}

/* Modal Content (image) */
.modal-content {
    margin: auto;
    display: block;
    width: 80%;
    max-width: 700px;
}

/* Caption of Modal Image */
#caption {
    margin: auto;
    display: block;
    width: 80%;
    max-width: 700px;
    text-align: center;
    color: #ccc;
    padding: 10px 0;
    height: 150px;
}

/* Add Animation */
.modal-content, #caption {    
    -webkit-animation-name: zoom;
    -webkit-animation-duration: 0.6s;
    animation-name: zoom;
    animation-duration: 0.6s;
}

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

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

/* The Close Button */
.close {
    position: absolute;
    top: 15px;
    right: 35px;
    color: #000;
    font-size: 40px;
    font-weight: bold;
    transition: 0.3s;
}

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

/* 100% Image Width on Smaller Screens */
@media only screen and (max-width: 700px){
    .modal-content {
        width: 100%;
    }
}
<img id="myImg" src="Almond.jpg" alt="almonds in factory" width="300" height="200">

<!-- The Modal -->
<div id="myModal" class="modal">
  <span class="close">&times;</span>
  <img class="modal-content" id="img01">
  <div id="caption"></div>
</div>

【问题讨论】:

标签: javascript html css button popup


【解决方案1】:

这是你需要的吗?(在放大的图片下在Modal中添加两个按钮)

如果我误解了你的问题,请告诉我,谢谢!

已编辑

多模态层的提示:

  1. 创建新的模态 div。

  2. 设置模态div不同的z-index。

  3. 最好让模态 div 有背景以避免重叠。

添加显示按钮以显示另一个模态:

// Get the modal
var modal1 = document.getElementById('myModal1');
var modal2 = document.getElementById('myModal2');

// Get the image and insert it inside the modal - use its "alt" text as a caption
var img = document.getElementById('myImg');
var modalImg1 = document.getElementById("img01");
var modalImg2 = document.getElementById("img02");
var captionText1 = document.getElementById("caption1");
var captionText2 = document.getElementById("caption2");
var enlarge = document.getElementById("enlarge");
var close_btn = document.getElementById("close-btn");
var close1 = document.getElementById("close1");
var close2 = document.getElementById("close2");
var show = document.getElementById("show");
img.onclick = function(){
    modal1.style.display = "block";
    modalImg1.src = this.src;
    captionText1.innerHTML = this.alt;
}
show.onclick = function(){
    modal2.style.display = "block";
    modalImg2.src = modalImg1.src;
    captionText2.innerHTML = "I'm the new " + captionText1.innerHTML;
}

// When the user clicks on <span> (x), close the modal
close_btn.onclick = function() { 
    modal1.style.display = "none";
};
close1.onclick = function() { 
    modal1.style.display = "none";
};
close2.onclick = function() { 
    modal2.style.display = "none";
};
/* Style the Image Used to Trigger the Modal */
#myImg {
    border-radius: 5px;
    cursor: pointer;
    transition: 0.3s;
}

#myImg:hover {opacity: 0.7;}

/* The Modal (background) */
.modal {
    display: none; /* Hidden by default */
    position: fixed; /* Stay in place */
    z-index: 1; /* Sit on top */
    padding-top: 100px; /* Location of the box */
    left: 0;
    top: 0;
    width: 100%; /* Full width */
    height: 100%; /* Full height */
    overflow: auto; /* Enable scroll if needed */
    background-color: transparent; /* Fallback color */
    background-color: transparent; /* Black w/ opacity */
}
#myModal2 {

    z-index: 2; /* Sit on top */
}
/* Modal Content (image) */
.modal-content {
    margin: auto;
    display: block;
    width: 80%;
    max-width: 700px;
}

/* Caption of Modal Image */
#caption1,#caption2 {
    margin: auto;
    display: block;
    width: 80%;
    max-width: 700px;
    text-align: center;
    color: #ccc;
    padding: 10px 0;
    height: 150px;
}
#buttons {
    margin: auto;
    display: block;
    width: 80%;
    max-width: 700px;
    text-align: center;
    color: #ccc;
    padding: 10px 0;
    height: 150px;
}

/* Add Animation */
.modal-content, #caption {    
    -webkit-animation-name: zoom;
    -webkit-animation-duration: 0.6s;
    animation-name: zoom;
    animation-duration: 0.6s;
}

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

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

/* The Close Button */
#close1, #close2 {
    position: absolute;
    top: 15px;
    right: 35px;
    color: #000;
    font-size: 40px;
    font-weight: bold;
    transition: 0.3s;
}

#close1:hover,
#close1:focus {
    color: #bbb;
    text-decoration: none;
    cursor: pointer;
}
#close2:hover,
#close2:focus {
    color: #bbb;
    text-decoration: none;
    cursor: pointer;
}

/* 100% Image Width on Smaller Screens */
@media only screen and (max-width: 700px){
    .modal-content {
        width: 100%;
    }
}
<img id="myImg" src="Almond.jpg" alt="almonds in factory" width="300" height="200">
  
<!-- The Modal -->
<div id="myModal1" class="modal">
  <span id="close1">&times;</span>
  <img class="modal-content" id="img01">
  <div id="buttons">
  <button id="show">show another</button>
  <button id="close-btn">close modal</button>
  </div>
  <div id="caption1"></div>
</div>

<!-- The Modal -->
<div id="myModal2" class="modal">
  <span id="close2">&times;</span>
  <img class="modal-content" id="img02">
  <div id="caption2"></div>
</div>

【讨论】:

  • 非常感谢特里,工作太棒了!不过,有一个问题,弹出窗口是否可以全屏显示,我正在使用 wpbakery。所以它只打开“行”的大小而不是屏幕。你的传奇哈哈
  • 一个模态 div 放在 body 下可以显示 100% 宽度 100% 高度以实现全屏
  • 甜蜜,工作...再次感谢 mil 特里非常感谢您的帮助,问题是,我需要这个来处理我的图像,当我复制 html 部分时,图像不会点击放大。非常感谢您的帮助。
  • 这基本上是一个画廊
猜你喜欢
  • 1970-01-01
  • 2013-05-09
  • 2011-01-16
  • 2011-07-29
  • 2022-12-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-05
相关资源
最近更新 更多