Trying to set up a sequence of autoplaying images has been a bit of a challenge for me. I've attempted various methods but haven't quite nailed it yet. Take a look at what I'm aiming for:
https://i.stack.imgur.com/JlqWk.gif
This is the code snippet that I currently have:
var mItemsCount = $(".home-m-item").length - 1;
setInterval(function() {
var t = $(".home-m-item.active");
t.removeClass("active");
if (t.index() === mItemsCount) {
$(".home-m-item:first").addClass("active");
} else {
t.next().addClass("active");
}
}, 200);
var windowPathname = window.location.host,
loader = $(".loader");
.home-m {
position: relative;
z-index: 3;
padding: 0 0 200px;
background: #111 url(assets/images/home/m-slant-bg.svg) bottom/100% 100% no-repeat;
}
a, a:active, a:focus, a:hover, a:link, a:visited {
outline: none;
}
.home-m-items {
position: absolute;
left: 1px;
top: 1px;
width: calc(100% - 2px);
height: calc(100% - 3px);
z-index: 1;
}
.home-m-item{
width: 100%;
height: 100%;
positoin: absolute;
left: 0;
top: 0;
background-repeat: no-repeat;
background-size: cover;
background-position: 50%;
visibility: hidden;
}
.home-m-item.active {visibility:visible}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="home-m">
<div class="home-m-items">
<div style="background-image: url('https://rossettibev.wpengine.com/wp-content/uploads/2020/08/R-Image-1.png');" class="home-m-item"></div>
<div style="background-image: url('https://rossettibev.wpengine.com/wp-content/uploads/2020/08/R-Image-3.png');" class="home-m-item"></div>
<div style="background-image: url('https://rossettibev.wpengine.com/wp-content/uploads/2020/08/R-Image-3.png');" class="home-m-item"></div>
<div style="background-image: url('https://rossettibev.wpengine.com/wp-content/uploads/2020/08/R-Image4.png');" class="home-m-item"></div>
<div style="background-image: url('https://rossettibev.wpengine.com/wp-content/uploads/2020/08/R-Image-5.png');" class="home-m-item"></div>
</div>
</div>
JavaScript animations are still new territory for me, so I suspect the issue lies within my script. However, I would also appreciate a solution achievable through keyframes.