Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery slick carousel "slide" setting

I have created a carousel using the jQuery slick plugin (http://kenwheeler.github.io/slick/). I would like to use the "slide" setting to specify which elements are used in the carousel. The description of this setting is:

Type:element
Default: ''
Element query to use as slide

My understanding of this setting is if I specify 'div', then only div elements will be displayed in the carousel. I cannot get this to work. When I create the carousel, all elements in the container are displayed.

I created a simple example:

<div class="slickContainer">
    <div class="slickItem">
        Item 1
    </div>
    <div class="slickItem">
        Item 2
    </div>
    <p>
        Shouldn't be an item.
    </p>
</div>

$(".slickContainer").slick({
      slide: 'div'
});

I also tried "slide: $('.slickItem')", but this didn't work either.

https://jsfiddle.net/Lobfdodo/

In the Result panel, if you click the left / right arrows you will see all three elements (div and p) in the carousel. I want only the div elements to be pulled into the carousel.

Any suggestions?

like image 927
joeshmoe301 Avatar asked May 04 '15 17:05

joeshmoe301


People also ask

How do you change the initial slide on slick slider?

You can use initialSlide for that. Note that the first slide has the number 0, so if you would like the slider to start from the second slide you would set initialSlide: 1 .

Does slick use jQuery?

Slick is a fresh new jQuery plugin for creating fully customizable, responsive and mobile friendly carousels/sliders that work with any html elements.


2 Answers

I had similar issue and could solve using following method:

$(".slickContainer").slick({
    slide: 'div',
    rows: 0
});
like image 179
Rijo Avatar answered Oct 13 '22 11:10

Rijo


I had a similar issue. The trick was, instantiate the slider, then filter out what you WANT to display.

Working Fiddle: https://jsfiddle.net/m8uxqrt3/

$(".slickContainer").slick().slick('slickFilter', '.slickItem');
like image 22
Red2678 Avatar answered Oct 13 '22 12:10

Red2678