完全响应和灵活 jQuery旋转木马插件 光滑

  • 源码大小:74.77KB
  • 所需积分:1积分
  • 源码编号:19JP-3289
  • 浏览次数:704次
  • 最后更新:2023年05月27日
  • 所属栏目:滑块
本站默认解压密码:19jp.com 或 19jp_com

简介

Slick是一个功能丰富的jQuery滑块插件,用于创建高度可定制、完全响应和移动友好的转盘/滑块,可与任何html元素一起使用。

特征:

  • 完全响应。适用于任何设备。
  • 在可用时使用CSS3。不起作用时完全起作用。
  • 已启用滑动。或者残疾,如果你愿意的话。
  • 无限循环。
  • 水平和垂直滚动。
  • 延迟加载和响应迅速的图像交付。
  • 自动播放、点、箭头、回调等。。。

参见:

  • 前50名最佳旋转木马jQuery插件

如何使用它:

1.在网页的标题部分包含核心和主题CSS。

  1. <link rel="stylesheet" href="/path/to/slick.css">
  2. <link rel="stylesheet" href="/path/to/slick-theme.css">

2.将要滑动的Html内容包裹在DIV元素中。

  1. <div class="slider demo">
  2. <div> Slide 1 </div>
  3. <div> Slide 2 </div>
  4. <div> Slide 3 </div>
  5. ...
  6. </div>

3.在页面底部包含最新版本的jQuery库和slick.js。

  1. <script src="/path/to/jquery.min.js"></script>
  2. <script src="/path/to/slick.js"></script>

4.调用您刚刚创建的旋转木马包装器上的插件。

  1. $(document).ready(function(){
  2. $('.demo').slick();
  3. });

5.可用于自定义转盘的选项。

  1. $('.demo').slick({
  2.  
  3. // Enables tabbing and arrow key navigation
  4. accessibility: true,
  5.  
  6. // Adapts slider height to the current slide
  7. adaptiveHeight: false,
  8.  
  9. // Change where the navigation arrows are attached (Selector, htmlString, Array, Element, jQuery object)
  10. appendArrows: $(element),
  11.  
  12. // Change where the navigation dots are attached (Selector, htmlString, Array, Element, jQuery object)
  13. appendDots: $(element),
  14.  
  15. // Enable Next/Prev arrows
  16. arrows: true,
  17.  
  18. // Sets the slider to be the navigation of other slider (Class or ID Name)
  19. asNavFor: null,
  20.  
  21. // prev arrow
  22. prevArrow: '<button type="button" data-role="none" class="slick-prev">Previous</button>',
  23.  
  24. // next arrow
  25. nextArrow: '<button type="button" data-role="none" class="slick-next">Next</button>',
  26.  
  27. // Enables auto play of slides
  28. autoplay: false,
  29.  
  30. // Auto play change interval
  31. autoplaySpeed: 3000,
  32.  
  33. // Enables centered view with partial prev/next slides.
  34. // Use with odd numbered slidesToShow counts.
  35. centerMode: false,
  36.  
  37. // Side padding when in center mode. (px or %)
  38. centerPadding: '50px',
  39.  
  40. // CSS3 easing
  41. cssEase: 'ease',
  42.  
  43. // Custom paging templates.
  44. customPaging: function(slider, i) {
  45. return '<button type="button" data-role="none">' + (i + 1) + '</button>';
  46. },
  47.  
  48. // Current slide indicator dots
  49. dots: false,
  50.  
  51. // Class for slide indicator dots container
  52. dotsClass: 'slick-dots',
  53.  
  54. // Enables desktop dragging
  55. draggable: true,
  56.  
  57. // animate() fallback easing
  58. easing: 'linear',
  59.  
  60. // Resistance when swiping edges of non-infinite carousels
  61. edgeFriction: 0.35,
  62.  
  63. // Enables fade
  64. fade: false,
  65.  
  66. // Focus on select and/or change
  67. focusOnSelect: false,
  68. focusOnChange: false,
  69.  
  70. // Infinite looping
  71. infinite: true,
  72.  
  73. // Initial slide
  74. initialSlide: 0,
  75.  
  76. // Accepts 'ondemand' or 'progressive' for lazy load technique
  77. lazyLoad: 'ondemand',
  78.  
  79. // Mobile first
  80. mobileFirst: false,
  81.  
  82. // Pauses autoplay on hover
  83. pauseOnHover: true,
  84.  
  85. // Pauses autoplay on focus
  86. pauseOnFocus: true,
  87.  
  88. // Pauses autoplay when a dot is hovered
  89. pauseOnDotsHover: false,
  90.  
  91. // Target containet to respond to
  92. respondTo: 'window',
  93.  
  94. // Breakpoint triggered settings
  95. /* eg
  96. responsive: [{
  97.  
  98. breakpoint: 1024,
  99. settings: {
  100. slidesToShow: 3,
  101. infinite: true
  102. }
  103.  
  104. }, {
  105.  
  106. breakpoint: 600,
  107. settings: {
  108. slidesToShow: 2,
  109. dots: true
  110. }
  111.  
  112. }, {
  113.  
  114. breakpoint: 300,
  115. settings: "unslick" // destroys slick
  116.  
  117. }]
  118. */
  119. responsive: null,
  120.  
  121. // Setting this to more than 1 initializes grid mode.
  122. // Use slidesPerRow to set how many slides should be in each row.
  123. rows: 1,
  124.  
  125. // Change the slider's direction to become right-to-left
  126. rtl: false,
  127.  
  128. // Slide element query
  129. slide: '',
  130.  
  131. // # of slides to show at a time
  132. slidesToShow: 1,
  133.  
  134. // With grid mode intialized via the rows option, this sets how many slides are in each grid row.
  135. slidesPerRow: 1,
  136.  
  137. // # of slides to scroll at a time
  138. slidesToScroll: 1,
  139.  
  140. // Transition speed
  141. speed: 500,
  142.  
  143. // Enables touch swipe
  144. swipe: true,
  145.  
  146. // Swipe to slide irrespective of slidesToScroll
  147. swipeToSlide: false,
  148.  
  149. // Enables slide moving with touch
  150. touchMove: true,
  151.  
  152. // To advance slides, the user must swipe a length of (1/touchThreshold) * the width of the slider.
  153. touchThreshold: 5,
  154.  
  155. // Enable/Disable CSS Transitions
  156. useCSS: true,
  157.  
  158. // Enable/Disable CSS Transforms
  159. useTransform: true,
  160.  
  161. // Disables automatic slide width calculation
  162. variableWidth: false,
  163.  
  164. // Vertical slide direction
  165. vertical: false,
  166.  
  167. // hanges swipe direction to vertical
  168. verticalSwiping: false,
  169.  
  170. // Ignores requests to advance the slide while animating
  171. waitForAnimate: true,
  172.  
  173. // Set the zIndex values for slides, useful for IE9 and lower
  174. zIndex: 1000
  175.  
  176. });

5.API方法。

  1. // destroys the plugin
  2. $('.demo').unslick();
  3.  
  4. // Triggers next slide
  5. $('.demo').slickNext();
  6.  
  7. // Triggers previous slide
  8. $('.demo').slickPrev();
  9.  
  10. // Pauses Autoplay
  11. $('.demo').slickPause();
  12.  
  13. // Starts Autoplay
  14. $('.demo').slickPlay();
  15.  
  16. // Goes to slide by index, skipping animation if second parameter is set to true
  17. $('.demo').slickGoTo(index,dontAnimate);
  18.  
  19. // Returns the current slide index
  20. $('.demo').slickCurrentSlide();
  21.  
  22. // Adds a slide. If an index is provided, will add at that index, or before if addBefore is set.
  23. // If no index is provided, add to the end or to the beginning if addBefore is set.
  24. // Accepts HTML String
  25. $('.demo').slickAdd(element,index,addBefore);
  26.  
  27. // Removes slide by index. If removeBefore is set true, remove slide preceding index, or the first slide if no index is specified.
  28. // If removeBefore is set to false, remove the slide following index, or the last slide if no index is set.
  29. $('.demo').slickRemove(index,removeBefore);
  30.  
  31. // Filters slides using jQuery .filter syntax
  32. $('.demo').slickFilter(filter);
  33.  
  34. // Removes applied filter
  35. $('.demo').slickUnfilter();
  36.  
  37. // Gets an option value.
  38. $('.demo').slickGetOption(option);
  39.  
  40. // Changes a single option to given value; refresh is optional.
  41. $('.demo').slickSetOption(option,value,refresh);
  42.  
  43. // Gets Slick Object
  44. $('.demo').getSlick();

6.事件处理程序。

  1. // Before slide change callback
  2. $('.demo').on('afterChange', function(event, slick, currentSlide){
  3. // do something
  4. });
  5.  
  6. // Before slide change callback
  7. $('.demo').on('beforeChange', function(event, slick, currentSlide, nextSlide){
  8. // do something
  9. });
  10.  
  11. // Fires after a breakpoint is hit
  12. $('.demo').on('breakpoint', function(event, slick, breakpoint){
  13. // do something
  14. });
  15.  
  16. // When slider is destroyed, or unslicked.
  17. $('.demo').on('destroy', function(event, slick){
  18. // do something
  19. });
  20.  
  21. // Fires when an edge is overscrolled in non-infinite mode.
  22. $('.demo').on('edge', function(event, slick, direction){
  23. // do something
  24. });
  25.  
  26. // When Slick initializes for the first time callback.
  27. // Note that this event should be defined before initializing the slider.
  28. $('.demo').on('init', function(event, slick){
  29. // do something
  30. });
  31.  
  32. // Every time Slick (re-)initializes callback
  33. $('.demo').on('reInit', function(event, slick){
  34. // do something
  35. });
  36.  
  37. // Every time Slick recalculates position
  38. $('.demo').on('setPosition', function(event, slick){
  39. // do something
  40. });
  41.  
  42. // Fires after swipe/drag
  43. $('.demo').on('swipe', function(event, slick, direction){
  44. // do something
  45. });
  46.  
  47. // Fires after image loads lazily
  48. $('.demo').on('lazyLoaded', function(event, slick, image, imageSource){
  49. // do something
  50. });
  51.  
  52. // Fires after image fails to load
  53. $('.demo').on('lazyLoadError', function(event, slick, image, imageSource){
  54. // do something
  55. });

更新日志:

2022-11-22

  • 文档已更新
  • 演示已更新

v1.9.0(2018年4月19日)

  • 使现代化

v1.5.9 (2016-02-05)

  • 使现代化

v1.4.0(2015年1月26日)

  • 使现代化

v1.3.3 (2014-04-09)

  • 修复firefox的菜单

v1.3.2 (2014-04-03)

  • 将上一个/下一个锚点更改为按钮标记
  • 更新样式
  • 更新占位符代码

v1.2.8 (2014-03-31)

  • 添加淡入淡出

v1.2.7 (2014-03-30)

  • 添加/删除项目补丁

v1.2.4 (2014-03-29)

  • 删除精灵,添加图标字体

v1.2.1 (2014-03-28)

  • 使现代化

 

预览截图