我想让滑块看起来像屏幕截图中的那样,即 nextSlide + 1 在顶部,我在代码中投入了。但我仍然不明白该怎么做。我想为 nextSlide 之后的元素分配一个类(在屏幕截图中它是第三个),并在它离开时将其删除。我希望我解释清楚,我附上截图。
<div class="main-arrow-container">
<div class="flex-f-slide">
<div class="slide-item-f">
<div class="slide-flex">
<div class="slide-flex-item1">
<div class='slide-img'><img src="https://bipbap.ru/wp-content/uploads/2017/10/0_8eb56_842bba74_XL-640x400.jpg" alt=""></div>
</div>
<div class="slide-flex-item2">
<div class='title-slide'>01</div>
<div class='title-descr'>lorem ipsum dolor</div>
</div>
</div>
</div>
<div class="slide-item-f">
<div class="slide-flex">
<div class="slide-flex-item1">
<div class='slide-img'><img src="https://bipbap.ru/wp-content/uploads/2017/10/0_8eb56_842bba74_XL-640x400.jpg" alt=""></div>
</div>
<div class="slide-flex-item2">
<div class='title-slide'>02</div>
<div class='title-descr'>lorem ipsum dolor</div>
</div>
</div>
</div>
<div class="slide-item-f">
<div class="slide-flex">
<div class="slide-flex-item1">
<div class='slide-img'><img src="https://bipbap.ru/wp-content/uploads/2017/10/0_8eb56_842bba74_XL-640x400.jpg" alt=""></div>
</div>
<div class="slide-flex-item2">
<div class='title-slide'>03</div>
<div class='title-descr'>lorem ipsum dolor</div>
</div>
</div>
</div>
<div class="slide-item-f">
<div class="slide-flex">
<div class="slide-flex-item1">
<div class='slide-img'><img src="https://bipbap.ru/wp-content/uploads/2017/10/0_8eb56_842bba74_XL-640x400.jpg" alt=""></div>
</div>
<div class="slide-flex-item2">
<div class='title-slide'>04</div>
<div class='title-descr'>lorem ipsum dolor</div>
</div>
</div>
</div>
</div>
</div>
.flex-f-slide{
.slick-slider {
margin-left: -12%;
margin-right: -12%;
}
.slick-list {
padding-top: 10%!important;
padding-bottom: 10%!important;
padding-left: 15%!important;
padding-right: 15%!important;
}
.slick-track {
max-width: 100%!important;
transform: translate3d(0, 0, 0)!important;
perspective: 100px;
}
.slick-slide {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
opacity: 0;
width: 100%!important;
transform: translate3d(0, 0, 0);
transition: transform 1s, opacity 1s;
}
.slick-snext,
.slick-sprev {
display: block;
}
.slick-current {
opacity: 1;
position: relative;
display: block;
transform: translate3d(0, 0, -10px);
z-index: 2;
}
.slick-snext {
opacity: 0.6;
transform: translate3d(30%, 0, 0px);
z-index: 1;
}
.slick-sprev {
opacity: 0.6;
transform: translate3d(-30%, 0, 0px);
}
.class_name{
opacity: 0.6;
transform: translate3d(-30%, 0, 0px);
}
.test {
display: block;
width: 100%;
height: 300px;
background: #c00;
box-shadow: inset 0px 0px 0px 3px #000
}
.slide-img{
img{
width: 306px;
height: 247px;
border-radius: 10px;
}
}
.slide-flex{
display: flex;
max-width: 615px;
margin: 0 auto;
border: 10px solid #1fbcde;
border-radius: 20px;
}
.title-slide{
font-family: @play;
font-weight: bold;
font-size: 32px;
letter-spacing: 0.1em;
}
.title-descr{
line-height: 21px;
letter-spacing: 0.1em;
font-size: 18px;
font-weight: 500;
color: #333333;
}
.slide-flex-item2{
padding-left: 48px;
padding-top: 20px;
background: #fff;
}
.flex-f-slide{
margin-top: 35px;
}
.main-arrow-container{
position: relative;
}
.prev-main-sl,
.next-main-sl {
position: absolute;
bottom: 0;
z-index: 2;
cursor: pointer;
}
.prev-main-sl{
right: 41%;
}
.next-main-sl{
right: 36%;
}
}
var rev = $('.flex-f-slide');
rev.on('init', function(event, slick, currentSlide) {
var
cur = $(slick.$slides[slick.currentSlide]),
next = cur.next(),
prev = cur.prev();
prev.addClass('slick-sprev');
next.addClass('slick-snext');
cur.removeClass('slick-snext').removeClass('slick-sprev');
slick.$prev = prev;
slick.$next = next;
}).on('beforeChange', function(event, slick, currentSlide, nextSlide) {
//console.log('beforeChange');
var
cur = $(slick.$slides[nextSlide]);
//console.log(slick.$prev, slick.$next);
slick.$prev.removeClass('slick-sprev');
slick.$next.removeClass('slick-snext');
next = cur.next(),
prev = cur.prev();
prev.prev();
prev.next();
prev.addClass('slick-sprev');
next.addClass('slick-snext');
slick.$prev = prev;
slick.$next = next;
cur.removeClass('slick-next').removeClass('slick-sprev');
});
rev.slick({
speed: 1000,
arrows: true,
dots: false,
focusOnSelect: true,
prevArrow: '<svg class="prev-main-sl" width="46" height="46" fill="none" xmlns="http://www.w3.org/2000/svg"><rect opacity=".5" width="46" height="46" rx="2" fill="#064070"/><rect x="3.173" y="3.172" width="39.655" height="39.655" rx="2" fill="#064070"/><rect x="3.173" y="3.172" width="39.655" height="39.655" rx="2" fill="#064070"/><rect x="3.173" y="3.172" width="39.655" height="39.655" rx="2" fill="#064070"/><path d="M11.983 22.293a1 1 0 000 1.414l6.364 6.364a1 1 0 001.414-1.414L14.104 23l5.657-5.657a1 1 0 00-1.414-1.414l-6.364 6.364zM33.31 22H12.69v2h20.62v-2z" fill="#fff"/></svg>',
nextArrow: '<svg class="next-main-sl" width="46" height="46" fill="none" xmlns="http://www.w3.org/2000/svg"><rect opacity=".5" x="46" y="46" width="46" height="46" rx="2" transform="rotate(-180 46 46)" fill="#064070"/><rect x="42.827" y="42.828" width="39.655" height="39.655" rx="2" transform="rotate(-180 42.827 42.828)" fill="#064070"/><rect x="42.827" y="42.828" width="39.655" height="39.655" rx="2" transform="rotate(-180 42.827 42.828)" fill="#064070"/><rect x="42.827" y="42.828" width="39.655" height="39.655" rx="2" transform="rotate(-180 42.827 42.828)" fill="#064070"/><path d="M34.017 23.707a1 1 0 000-1.414l-6.364-6.364a1 1 0 00-1.414 1.414L31.896 23l-5.657 5.657a1 1 0 101.414 1.414l6.364-6.364zM12.69 24H33.31v-2H12.69v2z" fill="#fff"/></svg>',
infinite: true,
centerMode: true,
slidesPerRow: 1,
slidesToShow: 1,
slidesToScroll: 1,
centerPadding: '0',
swipe: true,
customPaging: function(slider, i) {
return '';
},
/*infinite: false,*/
});
js
html
(图像数据作为数组传递给滑块渲染函数即使没有slick.js库的解决方案。最好在全屏模式下观看。