Reputation: 15
The first two listings work perfectly, especially if I remove the third and fourth from the code. The third listing doesn't show any images where it should, and the fourth shows all the images at once, until you click the next button, then they all disappear also.
Image of the webpage:
This is my main element that contains the listings
<main>
<h2>Latest Listings</h2>
<div class="main-gallery">
<div class="container">
<div class="mySlides1">
<div class="numbertext">1 / 3</div>
<img src="images/home1.1.jpg" alt="home demo image">
</div>
<div class="mySlides1">
<div class="numbertext">2 / 3</div>
<img src="images/home1.2.jpg" alt="home demo image">
</div>
<div class="mySlides1">
<div class="numbertext">3 / 3</div>
<img src="images/home1.3.jpg" alt="home demo image">
</div>
<button class="prev" onclick="plusDivs(-1, 0)">❮</button>
<button class="next" onclick="plusDivs(1, 0)">❯</button>
<div class="caption-container"><p>$608 / 3br - Townhouse</p></div>
</div>
<div class="container ">
<div class="mySlides2">
<div class="numbertext">1 / 5</div>
<img src="images/home2.1.jpg" alt="home demo image">
</div>
<div class="mySlides2">
<div class="numbertext">2 / 5</div>
<img src="images/home2.2.jpg" alt="home demo image">
</div>
<div class="mySlides2">
<div class="numbertext">3 / 5</div>
<img src="images/home2.3.jpg" alt="home demo image">
</div>
<div class="mySlides2">
<div class="numbertext">4 / 5</div>
<img src="images/home2.4.jpg" alt="home demo image">
</div>
<div class="mySlides2">
<div class="numbertext">5 / 5</div>
<img src="images/home2.5.jpg" alt="home demo image">
</div>
<button class="prev" onclick="plusDivs(-1, 1)">❮</button>
<button class="next" onclick="plusDivs(1, 1)">❯</button>
<div class="caption-container"><p>$685 / Fully Furnished, Beautiful 1-Bedroom Apt.</p></div>
</div>
<div class="container">
<div class="mySlides3">
<div class="numbertext">1 / 6</div>
<img src="images/home3.1.jpg" alt="home demo image">
</div>
<div class="mySlides3">
<div class="numbertext">2 / 6</div>
<img src="images/home3.2.jpg" alt="home demo image">
</div>
<div class="mySlides3">
<div class="numbertext">3 / 6</div>
<img src="images/home3.3.jpg" alt="home demo image">
</div>
<div class="mySlides3">
<div class="numbertext">4 / 6</div>
<img src="images/home3.4.jpg" alt="home demo image">
</div>
<div class="mySlides3">
<div class="numbertext">5 / 6</div>
<img src="images/home3.5.jpg" alt="home demo image">
</div>
<div class="mySlides3">
<div class="numbertext">6 / 6</div>
<img src="images/home3.6.jpg" alt="home demo image">
</div>
<button class="prev" onclick="plusDivs(-1, 2)">❮</button>
<button class="next" onclick="plusDivs(1, 2)">❯</button>
<div class="caption-container"><p>$1,000 / 2 Bedroom, 2 Bath Apartment DUPLEX</p></div>
</div>
<div class="container">
<div class="mySlides4">
<div class="numbertext">1 / 5</div>
<img src="images/home4.1.jpg" alt="home demo image">
</div>
<div class="mySlides4">
<div class="numbertext">2 / 5</div>
<img src="images/home4.2.jpg" alt="home demo image">
</div>
<div class="mySlides4">
<div class="numbertext">3 / 5</div>
<img src="images/home4.3.jpg" alt="home demo image">
</div>
<div class="mySlides4">
<div class="numbertext">4 / 5</div>
<img src="images/home4.4.jpg" alt="home demo image">
</div>
<div class="mySlides4">
<div class="numbertext">5 / 5</div>
<img src="images/home4.5.jpg" alt="home demo image">
</div>
<button class="prev" onclick="plusDivs(-1, 3)">❮</button>
<button class="next" onclick="plusDivs(1, 3)">❯</button>
<div class="caption-container"><p>$700 / Remodeled 2BR 1 BA with large yard</p></div>
</div>
</div>
</main>
Below is the javascript I used to cycle through the images in each slideshow
var slideIndex = [1,1];
var slideId = ["mySlides1", "mySlides2", "mySlides3", "mySlides4"];
showDivs(1, 0);
showDivs(1, 1);
showDivs(1, 2);
showDivs(1, 3);
function plusDivs(n, no) {
showDivs(slideIndex[no] += n, no);
}
function showDivs(n, no) {
var i;
var x = document.getElementsByClassName(slideId[no]);
if (n > x.length) {slideIndex[no] = 1}
if (n < 1) {slideIndex[no] = x.length}
for (i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
x[slideIndex[no]-1].style.display = "block";
}
This is the CSS being used:
main img {
vertical-align: middle;
height: 250px;
width: 100%;
border-radius: 10px 10px 0 0;
}
.main-gallery {
width: 120%;
display: flex;
overflow: hidden;
flex-direction: row;
padding: 10px;
margin: 0 auto;
}
/* Position the image container (needed to position the left and right arrows) */
.container {
position: relative;
width: 20%;
margin: 10px;
border-radius: 10px;
box-shadow: 10px 10px 15px #555;
}
/* Hide the images by default */
.mySlides {
display: none;
}
/* Add a pointer when hovering over the thumbnail images */
.cursor {
cursor: pointer;
}
/* Next & previous buttons */
.prev,
.next {
cursor: pointer;
position: absolute;
top: 40%;
width: auto;
padding: 16px;
border: none;
background: none;
margin-top: -50px;
color: white;
font-weight: bold;
font-size: 20px;
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.3);
}
.prev:focus,
.next:focus {
outline: none;
}
/* Number text (1/3 etc) */
.numbertext {
color: #f2f2f2;
font-size: 12px;
padding: 8px 12px;
position: absolute;
top: 0;
}
/* Container for image text */
.caption-container {
text-align: center;
background-color: #FFFFFF;
padding: 2px 16px;
border-radius: 10px;
color: #000000;
}
.row:after {
content: "";
display: table;
clear: both;
}
I am not sure what I did to make it not work, and I have spent days trying to find the mistake. That is why I am hoping someone can point out my error. Let me know if you need any other information to help.
Upvotes: 1
Views: 58
Reputation: 3589
The code you wrote requires you to add a new value of "1" to the "slideIndex" array for each slideshow
Replace
var slideIndex = [1, 1]
with this:
var slideIndex = [1, 1, 1, 1];
Upvotes: 1