JSFiddle - React, Tailwind, and code Playground
HTML
<div class="carousel_div">
<button onclick="pre_img()" class="btn previous"> ❰ </button>
<div class="img_frame"><img src="https://cdn.playeternalreturn.com/event/season1/firstseason/og_image_tra.png"></div>
<button onclick="next_img()" class="btn next"> ❱ </button>
</div>
CSS
.carousel_div{
width: 800px;
height: 450px;
border-width: 10px;
border-style: solid;
border-color: rgb(250, 176, 106);
}
.img_frame{
position: absolute;
width: 800px;
height: 450px;
text-align: center;
/*border: 1px solid blue;*/
}
.img_frame img{
max-width: 100%;
max-height: 100%;
}
.btn{
position: absolute;
z-index: 1;
width: 50px;
height: 450px;
font-size: 30px;
font-weight: bold;
border: 0;
background-color: rgba(255, 255, 255, 0.1);
transition: 0.5s;
}
.btn:hover{
background-color: rgba(255, 255, 255, 0.5);
}
.next{
margin-left: 750px;
}
JavaScript
var img_sort = 0;
var img_list = ['https://i.ytimg.com/vi/3-Excwt_pds/maxresdefault.jpg',
'https://i.ytimg.com/vi/U0PtZ1cijBs/maxresdefault.jpg',
'https://i.ytimg.com/vi/Gwk487DhkJo/maxresdefault.jpg',
'https://i.ytimg.com/vi/DaU0K-MjJpc/maxresdefault.jpg',
'https://i.ytimg.com/vi/lko26aX1Cqk/maxresdefault.jpg'];
img = document.querySelector('.img_frame img');
function pre_img(){
img.src = img_list[img_sort];
img_sort--;
if(img_sort < 0){
img_sort = 4;
}
}
function next_img(){
img.src = img_list[img_sort];
img_sort++;
if(img_sort > 4){
img_sort = 0;
}
}