slick

the last carousel you'll ever need

slick

the last carousel you'll ever need


单项轮播

1

2

3

4

5

6


$('.single-item').slick();
				

多项轮播

1

2

3

4

5

6

7

8

9


$('.multiple-items').slick({
  infinite: true,
  slidesToShow: 3,
  slidesToScroll: 3
});
				

响应式

1

2

3

4

5

6

7

8


$('.responsive').slick({
  dots: true,
  infinite: false,
  speed: 300,
  slidesToShow: 4,
  slidesToScroll: 4,
  responsive: [
    {
      breakpoint: 1024,
      settings: {
        slidesToShow: 3,
        slidesToScroll: 3,
        infinite: true,
        dots: true
      }
    },
    {
      breakpoint: 600,
      settings: {
        slidesToShow: 2,
        slidesToScroll: 2
      }
    },
    {
      breakpoint: 480,
      settings: {
        slidesToShow: 1,
        slidesToScroll: 1
      }
    }
  ]
});
				

一次轮播一个

1

2

3

4

5

6


$('.one-time').slick({
  dots: true,
  infinite: false,
  speed: 300,
  slidesToShow: 5,
  touchMove: false,
  slidesToScroll: 1
});
				

不均匀集

1

2

3

4

5

6


$('.uneven').slick({
  slidesToShow: 4,
  slidesToScroll: 4
});
				

中心模式

1

2

3

4

5

6


$('.center').slick({
  centerMode: true,
  centerPadding: '60px',
  slidesToShow: 3,
  responsive: [
    {
      breakpoint: 768,
      settings: {
        arrows: false,
        centerMode: true,
        centerPadding: '40px',
        slidesToShow: 3
      }
    },
    {
      breakpoint: 480,
      settings: {
        arrows: false,
        centerMode: true,
        centerPadding: '40px',
        slidesToShow: 1
      }
    }
  ]
});
				

延迟加载


// To use lazy loading, set a data-lazy attribute
// on your img tags and leave off the src

<img data-lazy="img/lazyfonz1.png"/>

$('.lazy').slick({
  lazyLoad: 'ondemand',
  slidesToShow: 3,
  slidesToScroll: 1
});
				

自动播放

1

2

3

4

5

6


$('.autoplay').slick({
  slidesToShow: 3,
  slidesToScroll: 1,
  autoplay: true,
  autoplaySpeed: 2000,
});
				

渐变效果


$('.fade').slick({
  dots: true,
  infinite: true,
  speed: 500,
  fade: true,
  slide: '> div',
  cssEase: 'linear'
});
				

添加和删除

1


$('.add-remove').slick({
  slidesToShow: 3,
  slidesToScroll: 3
});
var slideIndex = 1;
$('.js-add-slide').on('click', function(){
  slideIndex++;
  $('.add-remove').slickAdd('<div><h3>'+slideIndex+'</h3></div>');
});

$('.js-remove-slide').on('click', function(){
  $('.add-remove').slickRemove(slideIndex - 1);
  if (slideIndex !== 0) {
  	slideIndex--;
  }
});
				

过滤效果

1

2

3

4

5

6

7

8

9

10

11

12


$('.filtering').slick({
  slidesToShow: 4,
  slidesToScroll: 4
});

var filtered = false;

$('.js-filter').on('click', function(){
  if(filtered === false) {
    $('.filtering').slickFilter(':even');
    $(this).text('Unfilter Slides');
    filtered = true;
  } else {
    $('.filtering').slickUnfilter();
    $(this).text('Filter Slides');
    filtered = false;
  }
});
				

摧毁

If you really want to be that guy...


$('.your-slider').unslick();
				

配置API

属性 类型 默认 描述
accessibility boolean true Enables tabbing and arrow key navigation
autoplay boolean false Enables Autoplay
autoplaySpeed int(ms) 3000 Autoplay Speed in milliseconds
arrows boolean true Prev/Next Arrows
centerMode boolean false Enables centered view with partial prev/next slides. Use with odd numbered slidesToShow counts.
centerPadding string '50px' Side padding when in center mode (px or %)
cssEase string 'ease' CSS3 Animation Easing
customPaging function n/a Custom paging templates. See source for use example.
dots boolean false Show dot indicators
draggable boolean true Enable mouse dragging
fade boolean false Enable fade
easing string 'linear' Add easing for jQuery animate. Use with easing libraries or default easing methods
infinite boolean true Infinite loop sliding
lazyLoad string 'ondemand' Set lazy loading technique. Accepts 'ondemand' or 'progressive'.
onBeforeChange function null Before slide callback
onAfterChange function null After slide callback
onInit function null Callback that fires after first initialization
onReInit function null Callback that fires after every re-initialization
pauseOnHover boolean true Pause Autoplay On Hover
responsive object none Object containing breakpoints and settings objects (see demo). Enables settings sets at given screen width.
slide element 'div' Element query to use as slide
slidesToShow int 1 # of slides to show
slidesToScroll int 1 # of slides to scroll
speed int(ms) 300 Slide/Fade animation speed
swipe boolean true Enable swiping
touchMove boolean true Enable slide motion with touch
touchThreshold int 5 Swipe distance threshold
vertical boolean false Vertical slide mode

方法

方法 选项 描述
slickCurrentSlide none Returns the current slide index
slickGoTo int : slide number Navigates to a slide by index
slickNext none Navigates to the next slide
slickPrev none Navigates to the previous slide
slickPause none Pauses autoplay
slickPlay none Starts autoplay
slickAdd html or DOM object, index, addBefore Add a slide. If an index is provided, will add at that index, or before if addBefore is set. If no index is provided, add to the end or to the beginning if addBefore is set. Accepts HTML String || Object
slickRemove index, removeBefore Remove slide by index. If removeBefore is set true, remove slide preceding index, or the first slide if no index is specified. If removeBefore is set to false, remove the slide following index, or the last slide if no index is set.
slickFilter Selector or Function Filters slides using jQuery .filter()
slickUnfilter index Removes applied filtering
slickSetOption option : string, value : depends on option, refresh : boolean Sets an individual value live. Set refresh to true if it's a UI update.
unslick none Deconstructs slick