'I am trying to have multiple images on one html page
I am trying to have multiple images on one page where each image on click opens to a lightboxes gallery with around 6 additional images in each gallery.
I have tried adding a second modal changing the id name also and that did not help I am at a loss. I'm sure it is something simple and I'm just missing it.
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) {
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;
}
body {
font-family: Verdana, sans-serif;
margin: 0 200px;
}
* {
box-sizing: border-box;
}
.row > .column {
padding: 8px 8px 8px 8px ;
}
.row:after {
content: "";
display: table;
clear: both;
}
.column {
float: left;
width: 25%;
}
/* The Modal (background) */
.modal {
display: none;
position: fixed;
z-index: 1;
padding-top: 50px;
padding-right: 80px;
padding-left: 240px;
left: 0;
top: 0;
width:100% ;
height: 100%;
overflow: auto;
background-color: white;
}
/* Modal Content */
.modal-content {
position: relative;
background-color: #fefefe;
margin: auto;
padding: 2;
width: 100%;
max-width:800px;
}
/* The Close Button */
.close {
color: Gainsboro ;
position: absolute;
top: 10px;
right: 25px;
font-size: 25px;
font-weight: 100;
}
.close:hover,
.close:focus {
color: DarkSlateGray ;
text-decoration: none;
cursor: pointer;
}
.mySlides {
display: none;
}
.cursor {
cursor: pointer;
}
/* Next & previous buttons */
.prev,
.next {
cursor: pointer;
position: absolute;
top: 100%;
width: auto;
padding: 4px;
margin-top: -15px;
color: DarkSlateGray;
font-weight: 100;
font-size: 20px;
transition: 0.6s ease;
border-radius: 0 3px 3px 0;
user-select: none;
-webkit-user-select: none;
}
/* Position the "next button" to the right */
.next {
right: 0;
border-radius: 3px 0 0 3px;
}
/* On hover, add a black background color with a little bit see-through */
.prev:hover,
.next:hover {
background-color: rgba(0, 0, 0, 0.2);
}
/* Number text (1/3 etc) */
.numbertext {
color: DarkSlateGray;
font-size: 10px;
padding: 8px 12px;
position: absolute;
top: 0;
}
img {
margin-bottom: -4px;
}
.caption-container {
text-align: center;
background-color: white;
padding: 2px 16px;
color: white;
}
.demo {
opacity: 0.6;
}
.active,
.demo:hover {
opacity: 1;
}
img.hover-shadow {
transition: 0.3s;
}
.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);
}
<h2 style="text-align:center">News</h2>
<div class="row">
<div class="column">
<img src="img/news/lampoon/0-image.jpg" style="width:100%" onclick="openModal(myModal);currentSlide(1)" class="hover-shadow cursor">
</div>
<div class="row">
<div class="column">
<img src="img/news/autre/0-image.jpg" style="width:100%" onclick="openModal(myModal-autre);currentSlide(1)" class="hover-shadow cursor">
</div>
<div id="myModal" class="modal">
<span class="close cursor" onclick="closeModal(myModal)">×</span>
<div class="modal-content">
<div class="mySlides">
<div class="numbertext">1 / 2</div>
<img src="img/news/lampoon/01-image.jpg" style="width:100%">
</div>
<div class="mySlides">
<div class="numbertext">01 / 2</div>
<img src="img/news/lampoon/02-image.jpg" style="width:100%">
</div>
<a class="prev" onclick="plusSlides(-1)">❮</a>
<a class="next" onclick="plusSlides(1)">❯</a>
<div class="caption-container">
<p id="caption"></p>
</div>
<div id="myModal-autre" class="modal">
<span class="close cursor" onclick="closeModal(myModal-autre)">×</span>
<div class="modal-content">
<div class="mySlides">
<div class="numbertext">1 / 2</div>
<img src="img/news/autre/2-image.jpg" style="width:100%">
</div>
<div class="mySlides">
<div class="numbertext">01 / 2</div>
<img src="img/news/autre/02-image.jpg" style="width:100%">
</div>
<a class="prev" onclick="plusSlides(-1)">❮</a>
<a class="next" onclick="plusSlides(1)">❯</a>
<div class="caption-container">
<p id="caption"></p>
</div>
</div>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
