I'm creating a photo carousel. I have a list of several thumbnails but they are only visible 3 at a time. Clicking on one of them is shown below in large and with a text.
My theme is the organization of these three elements:
<p><</p>
lista de fotos
<p>></p>
The "button" to move forward positions me at the end of the list even though the photos are not visible ( display:none
). My idea is that the "button" to advance is at the end of the 3 visible photos. In the images, I think it's clearer.
var slideIndex = 1;
showDivs(slideIndex);
function plusDivs(n) {
showDivs(slideIndex += n);
}
function currentDiv(n) {
showDivs(slideIndex = n);
}
function showDivs(n) {
var i;
var x = document.getElementsByClassName("mySlides");
var dots = document.getElementsByClassName("demo");
if (n > x.length) {
slideIndex = 1
}
if (n < 1) {
slideIndex = x.length
}
for (i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
for (i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace(" w3-opacity-off", "");
}
x[slideIndex - 1].style.display = "block";
dots[slideIndex - 1].className += " w3-opacity-off";
}
var showNumber = 3;
var startPos = 0;
var endPos = showNumber;
var $List = $('ul li');
$List.hide().slice(startPos, endPos).fadeIn();
$('#adelante').click(function() {
if (endPos < $List.length) {
startPos = startPos + 1;
endPos = endPos + 1;
$List.hide().slice(startPos, endPos).fadeIn();
}
return false;
});
$('#atras').click(function() {
if (startPos > 0) {
startPos = startPos - 1;
endPos = endPos - 1;
$List.hide().slice(startPos, endPos).fadeIn();
}
return false;
});
@charset "utf-8";
li {
list-style-type: none;
}
div.w3-col {
padding-right: 5px;
}
.mySlides {
display: none
}
.demo {
cursor: pointer
}
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div>
<a id="atras" href="#" class="prev"><</a>
</div>
<div>
<ul>
<!-- Lista de seis fotos -->
<li>
<div class="w3-col s2">
<img src="https://public.slidesharecdn.com/images/user-48x48.png">
</div>
</li>
<li>
<div class="w3-col s2">
<img src="https://public.slidesharecdn.com/images/user-48x48.png">
</div>
</li>
<li>
<div class="w3-col s2">
<img src="https://public.slidesharecdn.com/images/user-48x48.png">
</li>
<li>
<div class="w3-col s2">
<img src="https://public.slidesharecdn.com/images/user-48x48.png">
</div>
</li>
<li>
<div class="w3-col s2">
<img src="https://public.slidesharecdn.com/images/user-48x48.png">
</div>
</li>
<li>
<div class="w3-col s2">
<img src="https://public.slidesharecdn.com/images/user-48x48.png">
</div>
</li>
</ul>
</div>
<div style="float:left; display:inline-block;">
<a id="adelante" href="#" class="next">></a>
</div>