最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Slick Carousel - centerMode without excess slides - Stack Overflow

programmeradmin1浏览0评论

I want to make a slide (using Slick.js), based on the picture, I want to make centerMode:true and focusOnSelect:true...

but the problem is there will be two excess slide (left and right). How do I remove them?

I already tried to set centerMode to false. There will be no excess slide, but the selected slide will be on the most left. So it is important for me to set the centerMode to true, because I want to make the selected slide in center.

Sorry for my bad english.

Any help will be appreciated.

Thanks

I want to make a slide (using Slick.js), based on the picture, I want to make centerMode:true and focusOnSelect:true...

but the problem is there will be two excess slide (left and right). How do I remove them?

I already tried to set centerMode to false. There will be no excess slide, but the selected slide will be on the most left. So it is important for me to set the centerMode to true, because I want to make the selected slide in center.

Sorry for my bad english.

Any help will be appreciated.

Thanks

Share Improve this question edited Mar 23, 2016 at 22:24 Yass 2,6683 gold badges15 silver badges21 bronze badges asked Mar 23, 2016 at 7:53 Syamsoul AzrienSyamsoul Azrien 2,7626 gold badges33 silver badges58 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

You could create a method that applies an opacity of 0 to the slide that appears before the first as well as to the slide that appears after the last i.e. the partial slides. You can call this method after initialization of the slider and after every slide change via the afterChange event:

function setSlideVisibility() {
  //Find the visible slides i.e. where aria-hidden="false"
  var visibleSlides = $('.slick-slide[aria-hidden="false"]');
  //Make sure all of the visible slides have an opacity of 1
  $(visibleSlides).each(function() {
    $(this).css('opacity', 1);
  });
  //Set the opacity of the first and last partial slides.
  $(visibleSlides).first().prev().css('opacity', 0);
  $(visibleSlides).last().next().css('opacity', 0);
}

$(setSlideVisibility());

$('.slider').on('afterChange', function() { 
  setSlideVisibility();
});

Fiddle Demo

I have a simpler solution. Work only in centerMode.

.slick-slide {
  opacity: 0;
}
.slick-slide.slick-center {
  opacity: 1;
}
发布评论

评论列表(0)

  1. 暂无评论