Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

README.markdown 12 KiB

3 år sedan
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. slick
  2. -------
  3. [1]: <https://github.com/kenwheeler/slick>
  4. _the last carousel you'll ever need_
  5. #### Demo
  6. [http://kenwheeler.github.io/slick](http://kenwheeler.github.io/slick/)
  7. #### CDN
  8. To start working with Slick right away, there's a couple of CDN choices availabile
  9. to serve the files as close, and fast as possible to your users:
  10. - https://cdnjs.com/libraries/slick-carousel
  11. - https://www.jsdelivr.com/projects/jquery.slick
  12. ##### Example using jsDelivr
  13. Just add a link to the css file in your `<head>`:
  14. ```html
  15. <!-- Add the slick-theme.css if you want default styling -->
  16. <link rel="stylesheet" type="text/css" href="//cdn.jsdelivr.net/gh/kenwheeler/slick@1.8.1/slick/slick.css"/>
  17. <!-- Add the slick-theme.css if you want default styling -->
  18. <link rel="stylesheet" type="text/css" href="//cdn.jsdelivr.net/gh/kenwheeler/slick@1.8.1/slick/slick-theme.css"/>
  19. ```
  20. Then, before your closing ```<body>``` tag add:
  21. ```html
  22. <script type="text/javascript" src="//cdn.jsdelivr.net/gh/kenwheeler/slick@1.8.1/slick/slick.min.js"></script>
  23. ```
  24. #### Package Managers
  25. ```sh
  26. # Bower
  27. bower install --save slick-carousel
  28. # NPM
  29. npm install slick-carousel
  30. ```
  31. #### Contributing
  32. PLEASE review CONTRIBUTING.markdown prior to requesting a feature, filing a pull request or filing an issue.
  33. ### Data Attribute Settings
  34. 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.
  35. Example:
  36. ```html
  37. <div data-slick='{"slidesToShow": 4, "slidesToScroll": 4}'>
  38. <div><h3>1</h3></div>
  39. <div><h3>2</h3></div>
  40. <div><h3>3</h3></div>
  41. <div><h3>4</h3></div>
  42. <div><h3>5</h3></div>
  43. <div><h3>6</h3></div>
  44. </div>
  45. ```
  46. ### Settings
  47. Option | Type | Default | Description
  48. ------ | ---- | ------- | -----------
  49. 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.
  50. adaptiveHeight | boolean | false | Adapts slider height to the current slide
  51. appendArrows | string | $(element) | Change where the navigation arrows are attached (Selector, htmlString, Array, Element, jQuery object)
  52. appendDots | string | $(element) | Change where the navigation dots are attached (Selector, htmlString, Array, Element, jQuery object)
  53. arrows | boolean | true | Enable Next/Prev arrows
  54. asNavFor | string | $(element) | Enables syncing of multiple sliders
  55. autoplay | boolean | false | Enables auto play of slides
  56. autoplaySpeed | int | 3000 | Auto play change interval
  57. centerMode | boolean | false | Enables centered view with partial prev/next slides. Use with odd numbered slidesToShow counts.
  58. centerPadding | string | '50px' | Side padding when in center mode. (px or %)
  59. cssEase | string | 'ease' | CSS3 easing
  60. customPaging | function | n/a | Custom paging templates. See source for use example.
  61. dots | boolean | false | Current slide indicator dots
  62. dotsClass | string | 'slick-dots' | Class for slide indicator dots container
  63. draggable | boolean | true | Enables desktop dragging
  64. easing | string | 'linear' | animate() fallback easing
  65. edgeFriction | integer | 0.15 | Resistance when swiping edges of non-infinite carousels
  66. fade | boolean | false | Enables fade
  67. focusOnSelect | boolean | false | Enable focus on selected element (click)
  68. focusOnChange | boolean | false | Puts focus on slide after change
  69. infinite | boolean | true | Infinite looping
  70. initialSlide | integer | 0 | Slide to start on
  71. 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.
  72. mobileFirst | boolean | false | Responsive settings use mobile first calculation
  73. 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.
  74. pauseOnDotsHover | boolean | false | Pauses autoplay when a dot is hovered
  75. pauseOnFocus | boolean | true | Pauses autoplay when slider is focussed
  76. pauseOnHover | boolean | true | Pauses autoplay on hover
  77. 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.
  78. respondTo | string | 'window' | Width that responsive object responds to. Can be 'window', 'slider' or 'min' (the smaller of the two).
  79. responsive | array | null | Array of objects [containing breakpoints and settings objects (see example)](#responsive-option-example). Enables settings at given `breakpoint`. Set `settings` to "unslick" instead of an object to disable slick at a given breakpoint.
  80. rows | int | 1 | Setting this to more than 1 initializes grid mode. Use slidesPerRow to set how many slides should be in each row.
  81. rtl | boolean | false | Change the slider's direction to become right-to-left
  82. slide | string | '' | Slide element query
  83. slidesPerRow | int | 1 | With grid mode initialized via the rows option, this sets how many slides are in each grid row.
  84. slidesToScroll | int | 1 | # of slides to scroll at a time
  85. slidesToShow | int | 1 | # of slides to show at a time
  86. speed | int | 300 | Transition speed
  87. swipe | boolean | true | Enables touch swipe
  88. swipeToSlide | boolean | false | Swipe to slide irrespective of slidesToScroll
  89. touchMove | boolean | true | Enables slide moving with touch
  90. touchThreshold | int | 5 | To advance slides, the user must swipe a length of (1/touchThreshold) * the width of the slider.
  91. useCSS | boolean | true | Enable/Disable CSS Transitions
  92. useTransform | boolean | true | Enable/Disable CSS Transforms
  93. variableWidth | boolean | false | Disables automatic slide width calculation
  94. vertical | boolean | false | Vertical slide direction
  95. verticalSwiping | boolean | false | Changes swipe direction to vertical
  96. waitForAnimate | boolean | true | Ignores requests to advance the slide while animating
  97. zIndex | number | 1000 | Set the zIndex values for slides, useful for IE9 and lower
  98. ##### Responsive Option Example
  99. The responsive option, and value, is quite unique and powerful.
  100. You can use it like so:
  101. ```javascript
  102. $(".slider").slick({
  103. // normal options...
  104. infinite: false,
  105. // the magic
  106. responsive: [{
  107. breakpoint: 1024,
  108. settings: {
  109. slidesToShow: 3,
  110. infinite: true
  111. }
  112. }, {
  113. breakpoint: 600,
  114. settings: {
  115. slidesToShow: 2,
  116. dots: true
  117. }
  118. }, {
  119. breakpoint: 300,
  120. settings: "unslick" // destroys slick
  121. }]
  122. });
  123. ```
  124. ### Events
  125. In slick 1.4, callback methods were deprecated and replaced with events. Use them before the initialization of slick as shown below:
  126. ```javascript
  127. // On swipe event
  128. $('.your-element').on('swipe', function(event, slick, direction){
  129. console.log(direction);
  130. // left
  131. });
  132. // On edge hit
  133. $('.your-element').on('edge', function(event, slick, direction){
  134. console.log('edge was hit')
  135. });
  136. // On before slide change
  137. $('.your-element').on('beforeChange', function(event, slick, currentSlide, nextSlide){
  138. console.log(nextSlide);
  139. });
  140. ```
  141. Event | Params | Description
  142. ------ | -------- | -----------
  143. afterChange | event, slick, currentSlide | After slide change callback
  144. beforeChange | event, slick, currentSlide, nextSlide | Before slide change callback
  145. breakpoint | event, slick, breakpoint | Fires after a breakpoint is hit
  146. destroy | event, slick | When slider is destroyed, or unslicked.
  147. edge | event, slick, direction | Fires when an edge is overscrolled in non-infinite mode.
  148. init | event, slick | When Slick initializes for the first time callback. Note that this event should be defined before initializing the slider.
  149. reInit | event, slick | Every time Slick (re-)initializes callback
  150. setPosition | event, slick | Every time Slick recalculates position
  151. swipe | event, slick, direction | Fires after swipe/drag
  152. lazyLoaded | event, slick, image, imageSource | Fires after image loads lazily
  153. lazyLoadError | event, slick, image, imageSource | Fires after image fails to load
  154. #### Methods
  155. Methods are called on slick instances through the slick method itself in version 1.4, see below:
  156. ```javascript
  157. // Add a slide
  158. $('.your-element').slick('slickAdd',"<div></div>");
  159. // Get the current slide
  160. var currentSlide = $('.your-element').slick('slickCurrentSlide');
  161. ```
  162. This new syntax allows you to call any internal slick method as well:
  163. ```javascript
  164. // Manually refresh positioning of slick
  165. $('.your-element').slick('setPosition');
  166. ```
  167. Method | Argument | Description
  168. ------ | -------- | -----------
  169. `slick` | options : object | Initializes Slick
  170. `unslick` | | Destroys Slick
  171. `slickNext` | | Triggers next slide
  172. `slickPrev` | | Triggers previous slide
  173. `slickPause` | | Pause Autoplay
  174. `slickPlay` | | Start Autoplay (_will also set `autoplay` option to `true`_)
  175. `slickGoTo` | index : int, dontAnimate : bool | Goes to slide by index, skipping animation if second parameter is set to true
  176. `slickCurrentSlide` | | Returns the current slide index
  177. `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 || Object
  178. `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.
  179. `slickFilter` | filter : selector or function | Filters slides using jQuery .filter syntax
  180. `slickUnfilter` | | Removes applied filter
  181. `slickGetOption` | option : string(option name) | Gets an option value.
  182. `slickSetOption` | change an option, `refresh` is always `boolean` and will update UI changes...
  183. | `option, value, refresh` | change a [single `option`](https://github.com/kenwheeler/slick#settings) to given `value`; `refresh` is optional.
  184. | `"responsive", [{ breakpoint: n, settings: {} }, ... ], refresh` | change or add [whole sets of responsive options](#responsive-option-example)
  185. | `{ option: value, option: value, ... }, refresh` | change [multiple `option`s](https://github.com/kenwheeler/slick#settings) to corresponding `value`s.
  186. #### Example
  187. Initialize with:
  188. ```javascript
  189. $(element).slick({
  190. dots: true,
  191. speed: 500
  192. });
  193. ```
  194. Change the speed with:
  195. ```javascript
  196. $(element).slick('slickSetOption', 'speed', 5000, true);
  197. ```
  198. Destroy with:
  199. ```javascript
  200. $(element).slick('unslick');
  201. ```
  202. #### Sass Variables
  203. Variable | Type | Default | Description
  204. ------ | ---- | ------- | -----------
  205. $slick-font-path | string | "./fonts/" | Directory path for the slick icon font
  206. $slick-font-family | string | "slick" | Font-family for slick icon font
  207. $slick-loader-path | string | "./" | Directory path for the loader image
  208. $slick-arrow-color | color | white | Color of the left/right arrow icons
  209. $slick-dot-color | color | black | Color of the navigation dots
  210. $slick-dot-color-active | color | $slick-dot-color | Color of the active navigation dot
  211. $slick-prev-character | string | '\2190' | Unicode character code for the previous arrow icon
  212. $slick-next-character | string | '\2192' | Unicode character code for the next arrow icon
  213. $slick-dot-character | string | '\2022' | Unicode character code for the navigation dot icon
  214. $slick-dot-size | pixels | 6px | Size of the navigation dots
  215. #### Browser support
  216. Slick works on IE8+ in addition to other modern browsers such as Chrome, Firefox, and Safari.
  217. #### Dependencies
  218. jQuery 1.7
  219. #### License
  220. Copyright (c) 2017 Ken Wheeler
  221. Licensed under the MIT license.
  222. Free as in Bacon.