Code Monkey home page Code Monkey logo

slick's Introduction

slick

the last carousel you'll ever need

Demo

http://kenwheeler.github.io/slick

CDN

To start working with Slick right away, there's a couple of CDN choices available to serve the files as close, and fast as possible to your users:

Example using jsDelivr

Just add a link to the css file in your <head>:

<!-- Add the slick-theme.css if you want default styling -->
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/[email protected]/slick/slick.css"/>
<!-- Add the slick-theme.css if you want default styling -->
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/[email protected]/slick/slick-theme.css"/>

Then, before your closing <body> tag add:

<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/[email protected]/slick/slick.min.js"></script>

Package Managers

# Bower
bower install --save slick-carousel

# NPM
npm install slick-carousel

Contributing

PLEASE review CONTRIBUTING.markdown prior to requesting a feature, filing a pull request or filing an issue.

Data Attribute Settings

In slick 1.5 you can now add settings using the data-slick attribute. You still need to call $(element).slick() to initialize slick on the element.

Example:

<div data-slick='{"slidesToShow": 4, "slidesToScroll": 4}'>
  <div><h3>1</h3></div>
  <div><h3>2</h3></div>
  <div><h3>3</h3></div>
  <div><h3>4</h3></div>
  <div><h3>5</h3></div>
  <div><h3>6</h3></div>
</div>

Settings

Option Type Default Description
accessibility boolean true Enables tabbing and arrow key navigation. Unless autoplay: true, sets browser focus to current slide (or first of current slide set, if multiple slidesToShow) after slide change. For full a11y compliance enable focusOnChange in addition to this.
adaptiveHeight boolean false Adapts slider height to the current slide
appendArrows string $(element) Change where the navigation arrows are attached (Selector, htmlString, Array, Element, jQuery object)
appendDots string $(element) Change where the navigation dots are attached (Selector, htmlString, Array, Element, jQuery object)
arrows boolean true Enable Next/Prev arrows
asNavFor string $(element) Enables syncing of multiple sliders
autoplay boolean false Enables auto play of slides
autoplaySpeed int 3000 Auto play change interval
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 easing
customPaging function n/a Custom paging templates. See source for use example.
dots boolean false Current slide indicator dots
dotsClass string 'slick-dots' Class for slide indicator dots container
draggable boolean true Enables desktop dragging
easing string 'linear' animate() fallback easing
edgeFriction integer 0.15 Resistance when swiping edges of non-infinite carousels
fade boolean false Enables fade
focusOnSelect boolean false Enable focus on selected element (click)
focusOnChange boolean false Puts focus on slide after change
infinite boolean true Infinite looping
initialSlide integer 0 Slide to start on
lazyLoad string 'ondemand' Accepts 'ondemand' or 'progressive' for lazy load technique. 'ondemand' will load the image as soon as you slide to it, 'progressive' loads one image after the other when the page loads.
mobileFirst boolean false Responsive settings use mobile first calculation
nextArrow string (html | jQuery selector) | object (DOM node | jQuery object) <button type="button" class="slick-next">Next</button> Allows you to select a node or customize the HTML for the "Next" arrow.
pauseOnDotsHover boolean false Pauses autoplay when a dot is hovered
pauseOnFocus boolean true Pauses autoplay when slider is focussed
pauseOnHover boolean true Pauses autoplay on hover
prevArrow string (html | jQuery selector) | object (DOM node | jQuery object) <button type="button" class="slick-prev">Previous</button> Allows you to select a node or customize the HTML for the "Previous" arrow.
respondTo string 'window' Width that responsive object responds to. Can be 'window', 'slider' or 'min' (the smaller of the two).
responsive array null Array of objects containing breakpoints and settings objects (see example). Enables settings at given breakpoint. Set settings to "unslick" instead of an object to disable slick at a given breakpoint.
rows int 1 Setting this to more than 1 initializes grid mode. Use slidesPerRow to set how many slides should be in each row.
rtl boolean false Change the slider's direction to become right-to-left
slide string '' Slide element query
slidesPerRow int 1 With grid mode initialized via the rows option, this sets how many slides are in each grid row.
slidesToScroll int 1 # of slides to scroll at a time
slidesToShow int 1 # of slides to show at a time
speed int 300 Transition speed
swipe boolean true Enables touch swipe
swipeToSlide boolean false Swipe to slide irrespective of slidesToScroll
touchMove boolean true Enables slide moving with touch
touchThreshold int 5 To advance slides, the user must swipe a length of (1/touchThreshold) * the width of the slider.
useCSS boolean true Enable/Disable CSS Transitions
useTransform boolean true Enable/Disable CSS Transforms
variableWidth boolean false Disables automatic slide width calculation
vertical boolean false Vertical slide direction
verticalSwiping boolean false Changes swipe direction to vertical
waitForAnimate boolean true Ignores requests to advance the slide while animating
zIndex number 1000 Set the zIndex values for slides, useful for IE9 and lower
Responsive Option Example

The responsive option, and value, is quite unique and powerful. You can use it like so:

$(".slider").slick({

  // normal options...
  infinite: false,

  // the magic
  responsive: [{

      breakpoint: 1024,
      settings: {
        slidesToShow: 3,
        infinite: true
      }

    }, {

      breakpoint: 600,
      settings: {
        slidesToShow: 2,
        dots: true
      }

    }, {

      breakpoint: 300,
      settings: "unslick" // destroys slick

    }]
});

Events

In slick 1.4, callback methods were deprecated and replaced with events. Use them before the initialization of slick as shown below:

// On swipe event
$('.your-element').on('swipe', function(event, slick, direction){
  console.log(direction);
  // left
});

// On edge hit
$('.your-element').on('edge', function(event, slick, direction){
  console.log('edge was hit')
});

// On before slide change
$('.your-element').on('beforeChange', function(event, slick, currentSlide, nextSlide){
  console.log(nextSlide);
});
Event Params Description
afterChange event, slick, currentSlide After slide change callback
beforeChange event, slick, currentSlide, nextSlide Before slide change callback
breakpoint event, slick, breakpoint Fires after a breakpoint is hit
destroy event, slick When slider is destroyed, or unslicked.
edge event, slick, direction Fires when an edge is overscrolled in non-infinite mode.
init event, slick When Slick initializes for the first time callback. Note that this event should be defined before initializing the slider.
reInit event, slick Every time Slick (re-)initializes callback
setPosition event, slick Every time Slick recalculates position
swipe event, slick, direction Fires after swipe/drag
lazyLoaded event, slick, image, imageSource Fires after image loads lazily
lazyLoadError event, slick, image, imageSource Fires after image fails to load

Methods

Methods are called on slick instances through the slick method itself in version 1.4, see below:

// Add a slide
$('.your-element').slick('slickAdd',"<div></div>");

// Get the current slide
var currentSlide = $('.your-element').slick('slickCurrentSlide');

This new syntax allows you to call any internal slick method as well:

// Manually refresh positioning of slick
$('.your-element').slick('setPosition');
Method Argument Description
slick options : object Initializes Slick
unslick Destroys Slick
slickNext Triggers next slide
slickPrev Triggers previous slide
slickPause Pause Autoplay
slickPlay Start Autoplay (will also set autoplay option to true)
slickGoTo index : int, dontAnimate : bool Goes to slide by index, skipping animation if second parameter is set to true
slickCurrentSlide Returns the current slide index
slickAdd element : html or DOM object, index: int, addBefore: bool 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
slickRemove index: int, removeBefore: bool 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 filter : selector or function Filters slides using jQuery .filter syntax
slickUnfilter Removes applied filter
slickGetOption option : string(option name) Gets an option value.
slickSetOption change an option, refresh is always boolean and will update UI changes...
option, value, refresh change a single option to given value; refresh is optional.
"responsive", [{ breakpoint: n, settings: {} }, ... ], refresh change or add whole sets of responsive options
{ option: value, option: value, ... }, refresh change multiple options to corresponding values.

Example

Initialize with:

$(element).slick({
  dots: true,
  speed: 500
});

Change the speed with:

$(element).slick('slickSetOption', 'speed', 5000, true);

Destroy with:

$(element).slick('unslick');

Sass Variables

Variable Type Default Description
$slick-font-path string "./fonts/" Directory path for the slick icon font
$slick-font-family string "slick" Font-family for slick icon font
$slick-loader-path string "./" Directory path for the loader image
$slick-arrow-color color white Color of the left/right arrow icons
$slick-dot-color color black Color of the navigation dots
$slick-dot-color-active color $slick-dot-color Color of the active navigation dot
$slick-prev-character string '\2190' Unicode character code for the previous arrow icon
$slick-next-character string '\2192' Unicode character code for the next arrow icon
$slick-dot-character string '\2022' Unicode character code for the navigation dot icon
$slick-dot-size pixels 6px Size of the navigation dots

Browser support

Slick works on IE8+ in addition to other modern browsers such as Chrome, Firefox, and Safari.

Dependencies

jQuery 1.7

License

Copyright (c) 2017 Ken Wheeler

Licensed under the MIT license.

Free as in Bacon.

slick's People

Contributors

ahmadalfy avatar avr avatar badlamer avatar cielt avatar cohenudi avatar colbyfayock avatar coliff avatar czajkowski avatar engelfrost avatar flaviocysne avatar fozzleberry avatar gflateman avatar kenwheeler avatar marcellscarlett avatar markvantilburg avatar mikedamage avatar millien avatar natewiley avatar paulschreiber avatar prayagverma avatar robharper avatar sebastiancichos avatar sharshenov avatar simeydotme avatar sirknightdragoon avatar stephenway avatar tanmancan avatar tbirdsall avatar wderuijter avatar wilirius avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

slick's Issues

Second active slide

How is it possible to make second slide in slider active instead of first?

I replaced code to _.dots.find('li').first().next().addClass('slick-active'); ,but it did not fix anything.

Thank you.

Keyboard Accessibility of links added to images

Just playing around with the demo and added a link (to wherever) to see how that would work because it's a common use case.

<div class="image">
  <a href="http://google.com/"><img src="img/fonz1.png"></a>
</div>

This worked fine if you hover over the image and click on it, but I couldn't get it to work with a keyboard if I tab in (I make sure I have focus by using the left/right arrow keys) and hit 'enter', nothing happens.

Tested this in Chrome on Windows (not on any other browser)

Add thumbnails functionality

I love your awesome plugin. I already started using it in a project. It works really well for banner slider. But there also is a product page where i have a thumbnail slider: http://i.imgur.com/htTb2Kj.jpg and i have to consider other plugins(which i think are not as good as yours) to implement it.

So i think it'd be really great if you added this functionality. Or maybe you know a way for me to do this now?

Thanks.

Smooth continuous scrolling?

Any plans to offer a smooth and continuous scrolling option? Sometimes one doesn't want an arrow for interaction, but just to have everything scroll by like a ticker tape.

Support RTL

Thanks for this great tool!
I'm just suggesting to support Right to Left mode to be useful for languages like Arabic.

Add 'crossFade: false' option

Current effect 'fade' can be described as 'crossFade' -- new slide appear on previous slide. In many-many situations this looks very bad..

Please, create option, for example 'crossFade: false', that change current animation to two steps:

  1. Current slide disappear (e.g. fadeOut())
  2. New slide appear (e.g. fadeIn());

Bind Click?

I'm attempting to perform a jQuery function upon images in my slick carousel, but I'm finding it hard to select them.

$('img').click(

Works for static images, but it doesn't seem to work for anything within a slick carousel.

Any ideas? Thanks.

Issue with 'active' class not applied/clearing as expected on cloned items

Great script. One slight bug is the 'active' class not being cleared from cloned items at the right hand side of an infinite list. Also 'active' only seems to get applied when carousel moves beyond first position. Doesn't trigger on script init nor when the carousel has completed a full loop.

Sadly dev project is behind locked doors so can't show live example at present.

Multiple carousels getting pulled into the first

On a page with multiple carousels - all carousel items from every carousel are pulled into the first carousel. Attempted to use this on a product page where every product would have a mini carousel of a few images you could look through, but this pulls every product image into the first carousel.

Easily reproducible in your sample index.html, just duplicate the first block and you can see the results

Ex.

<div class="slider single-item">
    <div class="multiple"><h3>1</h3></div>
    <div class="multiple"><h3>2</h3></div>
    <div class="multiple"><h3>3</h3></div>
    <div class="multiple"><h3>4</h3></div>
    <div class="multiple"><h3>5</h3></div>
    <div class="multiple"><h3>6</h3></div>
</div>

<div class="slider single-item">
    <div class="multiple"><h3>1</h3></div>
    <div class="multiple"><h3>2</h3></div>
    <div class="multiple"><h3>3</h3></div>
    <div class="multiple"><h3>4</h3></div>
    <div class="multiple"><h3>5</h3></div>
    <div class="multiple"><h3>6</h3></div>
</div>
// JS
$('.slick').slick();

Cheers!

Ian

Bower?

Carousels are terrible but if I had to list one as a dependency, I would do it via bower.

Would you accept a PR with all the Bower metadata in tow?

Min/Max ranges for Multiple Items

Hey, I'm yet to use your slider, but it seems we might finally have an alternative to flexslider!

I was just reading through the docs and noticed you don't provide a min/max range for multiple items.

I use sliders pretty much on a daily basis and I'm often required to use this feature, unfortunately it's pretty buggy in flexslider.

I think it would make a really good addition to your slider.

How can I get Slick to maintain a slide's dimensions?

Very timely post yesterday; I'm working on a page that emulates an iPad carousel, with pages of items. I had it mostly working with iScroll, but started running into problems right before you posted Slick.

So I'm trying it out, but once I initialize it, the dimensions get screwed up so that a page of 12 items (3 rows of 4) winds up being the height of a single item.

The DOM structure is like this:

ul#pages
    li.page
        div.item
        div.item
        div.item
        ...
    li.page
        div.item
        div.item
        div.item
        ...

I started playing with

Slick.prototype.setDimensions()

but haven't made much progress.

Any idea how I might achieve this behavior -- carousel elements that are sized according to their contents -- using Slick?

Before:

screenshot 1

and after:

screenshot 2

Thanks so much...

Slides stick to cursor after dragging and then resizing

When you drag the slides a single time, then using your own responsive method, resize and alter the slide number.

If you enter slick's area, the slides move to the sides with your cursor.

Clicking or moving out of the area sets them correctly and then they do not follow the cursor further.

Rather annoying when attempting to use it!

Autoplay issue with responsive.

Currently, if you have autoplay set to true and multiple media queries the animations start to stack up when moving between queries.

For example, if I have autoplay as true on a mobile query, resize up to tablet, if autoplay is also true, the animations will double up. If tablet query is false, the mobile autoplay animations continue anyway.

Slider have margin-bottom

Firstly, I want say: thank you for the great slider! ;)

Secondly, I have question/issue: why you add "margin-bottom: 30px" in .slick-slider?
This is good in demo page, but in real projects, we always should override this rule...

Change speed on the go

Can I manipulate slick speed after it's initialized?

Very need this feature... :) May be you can add this as method?

Add BoxSlider's transition effects

I've compared all available sliders on the github, jquery plugins and themeforest. Only very few are complete and usable and maintain clean code. Fotorama.io is one of those, but it also lacks at one point, just like Slick: Transition Effects.

I just point you to an awesome slider, which only lacks your features to be perfect, or vice versa. You can merge the effects of box-slider into Slick, if you want. It's written cleanly and each effect is in it's separate file. Here's the source: https://github.com/p-m-p/jquery-box-slider

Clicking on the next/prev arrows rapidly causes repeat animations

Currently, if you click on the next or previous arrows rapidly, the current animation repeats until the transition time is finished, then it goes to the next slide.

Optimally, the number of clicks should equal the number of transitions. It's especially noticeable in the "Autoplay" demo or when the transition speed is slow.

Mouse and touch interaction are both affected.

pauseOnHover is ignored if dot is clicked

Despite the documentation stating that the default is true, it appears this is not so.

Okay, after further testing, it appears that it is. It definitely was not when I first tested it.

I'll see if something is causing this to change.

Youtube Playback

Hi, any chance you'll add support to add youtube videos in the carousel?
(with things like pausing the video when switching slides and pausing the slides when playing a video)

Component

Add this to component - awesome job on this!

Add a license file

The readme references the type of licenses but doesn't link to the license language. I think it would be best to add the actual license to the repo.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.