Для чего бы то ни было, ваш код не работает должным образом, когда добавлено более двух слайдов.
Чтобы исправить это, вам нужно добавить код, чтобы правильно изменить направление. Я разветвил предыдущее решение и решил, что с помощью javascript вызова
<a href="#" class="arrow left" onclick="carousel(-1)"></a>
вместо
<a href="#" class="arrow left" onclick="carousel(1)"></a>
для левого индикатора.
Я также добавил logi c, чтобы проверить, является ли направление обратным, и текущий слайд - Слайд 1 (требующий, чтобы индекс слайда отражал последний слайд).
if (slideIndex > x.length) {
slideIndex = 1
} else if (inc == -1 && slideIndex < 1) {
slideIndex = x.length;
}
Относительно вашего исходного вопроса (как добавить стрелки и где поставить код для стрелок):
Как показано в CSS предыдущего ответа, позиция «абсолютная», а также калькулятор сверху: cal c (100% 2) позволяет определить, где находится вертикальная половина пути для карусели.
Right 0 (с .arrow.right) заставляет стрелку вправо оставаться с правой стороны карусели (0 означает крайний правый угол) , Z-индекс указывает, что он должен быть выше карусели (второй слой).
.arrow{
display: block;
position: absolute;
z-index: 2;
text-decoration: none;
top: calc(100%/2);
font-size: 30px;
color: black;
}
.arrow.right{
right: 0;
}
var slideIndex = 0;
carousel(1);
function carousel(inc = 1) {
var i;
var x = document.getElementsByClassName("mySlides");
for (i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
slideIndex += inc;
if (slideIndex > x.length) {
slideIndex = 1
} else if (inc == -1 && slideIndex < 1) {
slideIndex = x.length;
}
x[slideIndex - 1].style.display = "block";
}
.container{
position: relative
}
.white-title {
margin-top: 30px;
margin-bottom: 30px;
-webkit-transform: translate(0px, 0px);
-ms-transform: translate(0px, 0px);
transform: translate(0px, 0px);
font-family: Lato, sans-serif;
color: #fff;
font-size: 40px;
font-weight: 300;
text-align: center;
}
.white-title.fact {
margin-bottom: 50px;
-webkit-transition: all 500ms ease;
transition: all 500ms ease;
font-family: Raleway, sans-serif;
color: #fff;
font-size: 80px;
font-weight: 100;
}
.white-title.auvik {
font-style: italic;
font-weight: 900;
}
.white-title.link {
color: #ffffff;
font-style: italic;
font-weight: 900;
text-decoration: none;
text-transform: uppercase;
}
.white-title.link:hover {
color: #ffffff;
text-decoration: none;
text-transform: uppercase;
}
.mySlides {
display: none;
padding: 100px;
text-align: center;
height: 250px;
}
.slide-datto,
.slide-datto-hover:hover {
color: #fff !important;
background-color: blue !important
}
.slide-auvik,
.slide-auvik-hover:hover {
color: #fff !important;
background-color: yellow !important
}
.arrow{
display: block;
position: absolute;
z-index: 2;
text-decoration: none;
top: calc(100%/2);
font-size: 30px;
color: black;
}
.arrow.left{
}
.arrow.right{
right: 0;
}