I've been using this slider that I've whittled down to exactly what I need. Now I'm trying to add a fade effect between slides. I'm still learning jquery, specifically the var function. Here's the code that's at play:
JQUERY
(function ($) {
$(function () {
var currentIndex = 0,
items = $('.unique-slider div'),
itemAmt = items.length;
function cycleItems() {
var item = $('.unique-slider div').eq(currentIndex);
items.hide();
item.css('display', 'inline-block');
}
var autoSlide = setInterval(function () {
currentIndex += 1;
if (currentIndex > itemAmt - 1) {
currentIndex = 0;
}
cycleItems();
}, 3000);
$('#right').click(function () {
currentIndex += 1;
if (currentIndex > itemAmt - 1) {
currentIndex = 0;
}
cycleItems();
});
$('#left').click(function () {
currentIndex -= 1;
if (currentIndex < 0) {
currentIndex = itemAmt - 1;
}
cycleItems();
});
});
})(jQuery);
HTML
<section class='slider-body'>
<div id='left' class='arrows'>
<img src='/wp-content/uploads/2017/01/left.png'>
</div>
<div id='right' class='arrows'>
<img src='/wp-content/uploads/2017/01/right.png'>
</div>
<div class='slider unique-slider'>
<div class='slide' style='display: inline-block;'>
<img class='img-slide' src='SOURCE'/>
</div>
<div class='slide'>
<img class='img-slide' src='SOURCE'/>
</div>
</div>
</section>
CSS
.slider-body {
position: relative;
width: auto;
overflow: hidden;
}
.slider {
position: relative;
width: 100vw;
height: auto;
margin: 0 auto;
text-align: center;
}
.slider div {
display: inline-block;
display: none;
background-color: white;
width: 100%;
}
.slide {
height: 100%;
}
.img-slide {
position: relative;
margin: 0 auto;
height: 100vh;
}
#test-right,
#right {
right: 5px;
padding-left: 5px;
}
#test-left,
#left {
left: 5px;
padding-right: 5px;
}
.arrows {
z-index: 20;
position: absolute;
top: 0;
bottom: 0;
margin: auto;
width: 40px;
height: 40px;
padding: 5px;
background-color: #ffffff;
opacity: 0.7
}