Angelinasen,
<!DOCTYPE html>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<style type="text/css">
.mySlider__container {
display: flex;
flex-direction: column;
border: 1px solid #0000FF;
width: 680px;
margin: 0px auto;
}
.mySlider__wrapper {
position: relative;
width: 640px;
height: 320px;
overflow: hidden;
margin: 20px auto;
}
.mySlider__wrapper>div {
display: none;
position: absolute;
}
.mySlider__dots {
display: flex;
justify-content: space-between;
width: 70px;
margin: 0px auto 15px;
}
.mySlider__dots li {
background-color: #000000;
border-radius: 50px;
;
width: 10px;
height: 10px;
overflow: hidden;
cursor: default;
list-style: none;
}
.mySlider__dots li.active {
background-color: #0000FF;
}
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script>
(function($) {
$.fn.mySlider = function(interval) {
let container = $('.mySlider__container');
let slides = $('.mySlider__wrapper > div');
let dots = container.find('.mySlider__dots li');
let amount = slides.length;
let index = amount - 1;
let timer;
let auto = true;
dots.each((i, el) => $(el).on('click', _ => {
auto = false;
changeSlides(i - index);
}))
function changeSlides(i = 1) {
window.clearTimeout(timer);
$(slides[index]).fadeOut(300);
$(dots[index]).removeClass('active');
index = (amount + index + i) % amount;
$(slides[index]).delay(100).fadeIn(1000);
$(dots[index]).addClass('active');
if (auto) timer = setTimeout(changeSlides, interval);
}
container.mouseleave(function() {
if (!auto) {
auto = true;
changeSlides();
}
})
changeSlides()
};
})(jQuery);
$(function() {
$.fn.mySlider(3000)
});
</script>
</head>
<body>
<div class="mySlider__container">
<div class="mySlider__wrapper">
<div class="mySlider__slide"><img src="https://picsum.photos/640/320?1"></div>
<div class="mySlider__slide"><img src="https://picsum.photos/640/320?2"></div>
<div class="mySlider__slide"><img src="https://picsum.photos/640/320?3"></div>
<div class="mySlider__slide"><img src="https://picsum.photos/640/320?4"></div>
</div>
<ul class="mySlider__dots">
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>
</body>
</html>