So I want to add a transition effect to those images when they change through the buttons but I'm not sure how to do that or either do it on main style CSS or through the attributes with JavaScript.
For example, giving it something like this : transition: 2s linear
.
var number;
var imagecount = document.getElementsByClassName('images');
function imageshow(b) {
for (var i = 0; i < imagecount.length; i++) {
if (i == b) {
imagecount[i].style.display = 'block';
number = i;
} else {
imagecount[i].style.display = 'none';
}
}
}
function prev(number) {
imageshow(number - 1)
if (number == 0) {
imageshow(imagecount.length - 1);
}
}
function next(number) {
imageshow(number + 1)
if (number == imagecount.length - 1) {
imageshow(0);
}
}
imageshow(0);
body {
margin: 0px;
}
.images {
width: 700px;
height: 500px;
border-radius: 11px;
border: outset 2px rgba(70, 70, 70, 0.616);
}
#slider {
font-family: Arial, Helvetica, sans-serif;
}
<div id="slider">
<img src="https://i.picsum.photos/id/874/536/354.jpg" class="images" alt="">
<img src="https://i.picsum.photos/id/99/536/354.jpg" class="images" alt="">
<img src="https://i.picsum.photos/id/684/536/354.jpg" class="images" alt="">
<img src="https://i.picsum.photos/id/556/536/354.jpg" class="images" alt="">
<img src="https://i.picsum.photos/id/886/536/354.jpg" class="images" alt=""><br>
<button onclick="prev(number)">previous</button>
<button onclick="next(number)">next</button>
</div>