Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slick Carousel - centerMode without excess slides

Tags:

enter image description here

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

like image 979
Syamsoul Azrien Avatar asked Mar 23 '16 07:03

Syamsoul Azrien


People also ask

How do you show half slider on slick slider?

Either you can give a fixed padding to the right or percentage. You can do something like this slidesToShow: 3.5 and make infinite: false . The right most slide will be showing half.

What is carousel in slick?

The carousel is a slideshow for cycling through a series of content, built with CSS 3D transforms and a bit of JavaScript. It works with a series of images, text, or custom markup. It also includes support for previous/next controls and indicators. Official documentation.


1 Answers

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

like image 107
Yass Avatar answered Oct 11 '22 05:10

Yass