I have a slider and under each individual slide I would like to display two divs with a description depending on which slide is active.
var swiper = new Swiper('.swiper-container.about', {
effect: 'coverflow',
initialSlide: 1,
grabCursor: true,
centeredSlides: true,
slidesPerView: 'auto',
coverflowEffect: {
rotate: 0,
stretch: 0,
depth: 800,
modifier: 1,
slideShadows: true,
},
pagination: {
el: '.swiper-pagination',
}
});
.swiper-container.about {
width: 100%;
padding-top: 200px;
padding-bottom: 50px;
height: 100vh;
}
.swiper-slide.about {
background-position: center;
background-size: cover;
width: 300px;
height: 400px !important;
background-color: rgb(216, 155, 0);
}
.swiper-slide .imgBx {
width: 100%;
height: 300px;
overflow: hidden;
}
.swiper-slide .imgBx img {
width: 100%;
}
.swiper-slide .employee {
width: 100%;
box-sizing: border-box;
padding: 20px;
}
.swiper-slide .employee h3 {
margin: 0;
padding: 0;
font-size: 20px;
text-align: center;
line-height: 30px;
}
.swiper-slide .employee h3 span {
font-size: 16px;
color: white;
}
.employee-details-text {
font-family: 'EB Garamond', serif !important;
background-color: black;
color: white;
position: absolute;
top: 53%;
left: 50%;
transform: translate(-50%, -50%);
display: block;
}
.employee-details-note {
font-family: 'EB Garamond', serif !important;
background-color: black;
color: white;
position: absolute;
top: 53%;
left: 50%;
transform: translate(-50%, -50%);
display: block;
}
.swiper-container .swiper-wrapper .swiper-slide~.employee-details-text,
.swiper-container .swiper-wrapper .swiper-slide~.employee-details-note {
display: none;
}
.swiper-slide.swiper-slide-active+.employee-details-text,
.swiper-slide.swiper-slide-active+.employee-details-note {
display: block;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.5.0/js/swiper.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.5.0/css/swiper.min.css" rel="stylesheet" />
<div class="swiper-container about">
<div class="swiper-wrapper">
<div class="swiper-slide about">
<div class="imgBx">
<img src="tom.jpg">
</div>
<div class="employee">
<h3>Tom<br><span>Travel production manager</span></h3>
</div>
</div>
<div class="swiper-slide about">
<div class="imgBx">
<img src="annie.jpg">
</div>
<div class="employee">
<h3>Annie<br><span>Co-founder and Finance manager</span></h3>
</div>
</div>
<div class="swiper-slide about">
<div class="imgBx">
<img src="suzan.jpg">
</div>
<div class="employee">
<h3>Suzan<br><span>Travel manager</span></h3>
</div>
</div>
</div>
<!-- Add Arrows -->
<div class="swiper-button-next"></div>
<div class="swiper-button-prev"></div>
</div>
<div class="employee-details-text">
Description employee one
</div>
<div class="employee-details-note">
Note employee one
</div>
<div class="employee-details-text">
Description employee two
</div>
<div class="employee-details-note">
Note employee two
</div>
<div class="employee-details-text">
Description employee three
</div>
<div class="employee-details-note">
Note employee three
</div>
So under every employee slide I would like to display their description.
Here is simple sketch of how it should look:
The Div with the description is outside of the
<div class="swiper-container about"> div.
When the slide is active, the class swiper-slide-active is added to
<div class="swiper-slide about">
I am trying to use the combinator ~ selector to connect the active slide with the proper description divs so I added this css code:
.swiper-container .swiper-wrapper .swiper-slide~.employee-details-text,
.swiper-container .swiper-wrapper .swiper-slide~.employee-details-note {
display: none;
}
.swiper-slide.swiper-slide-active+.employee-details-text,
.swiper-slide.swiper-slide-active+.employee-details-note {
display: block;
}
This doesn't seem to work. All descriptions are displayed at once. Not sure what am I missing, any advice is highly appreciated.
