比Swiper更简单易用滑块幻灯片Slick.js

Slick.js 简介

Slick.js是一个流行的、‌基于jQuery的响应式轮播插件,‌用于创建漂亮的滑块导航和轮播效果。‌Slick.js的主要特点包括响应式设计,‌可以自动适应不同屏幕尺寸和设备类型;‌多样化的过渡效果,‌如滑动、‌淡入淡出等;‌支持无限循环和自动播放;‌以及提供了导航箭头和分页器功能,‌方便用户进行滑块的导航和切换。‌Slick.js适用于各种需要展示多个内容块的场景,‌如产品展示、‌图片展览等‌。了解更多官网地址:https://kenwheeler.github.io/slick/

特征

  • 完全响应。随其容器缩放。
  • 每个断点单独设置
  • 可用时使用 CSS3。不可用时可完全正常运行。
  • 已启用滑动功能。或者,如果您愿意,也可以禁用。
  • 桌面鼠标拖动
  • 无限循环。
  • 通过箭头键导航即可轻松访问
  • 添加、删除、过滤和取消过滤幻灯片
  • 自动播放、点、箭头、回调等……

Swiper 简介

Swiper(‌前称Swiper master)‌是一款免费且轻量级的移动设备触控滑块的js框架,‌主要面向移动端的网站、‌网页应用程序以及原生应用程序。‌它使用硬件加速过渡,‌为IOS设计同时也兼容Android、‌WP8系统以及PC端浏览器,‌提供良好的用户体验。‌Swiper功能强大,‌能实现触屏焦点图、‌触屏Tab切换、‌触屏轮播图切换等效果,‌且易于使用,‌通过简单的配置即可实现。‌此外,‌Swiper开源、‌稳定,‌拥有广泛的应用和活跃的社区,‌是网页设计师必备的技能之一,‌被众多知名品牌所使用‌。了解更多官网地址:https://swiperjs.com/

横向比较Slick.js与Swiper,各自核心特点:Slick.js比Swiper更加简单易用;Swiper比Slick.js更加功能丰富!

Slick.js 入门

1、设置您的 HTML 标记。

<div class="your-class">
  <div>your content</div>
  <div>your content</div>
  <div>your content</div>
</div>

2、将 /slick 文件夹移动到你的项目中

在 <head> 中添加 slick.css

<link rel="stylesheet" type="text/css" href="slick/slick.css"/>
// Add the new slick-theme.css if you want the default styling
<link rel="stylesheet" type="text/css" href="slick/slick-theme.css"/>

在结束 <body> 标签之前、jQuery 之后添加 slick.js(需要 jQuery 1.7 +)

<script type="text/javascript" src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script type="text/javascript" src="slick/slick.min.js"></script>

3、在脚本文件或内联脚本标签中初始化滑块

$(document).ready(function(){
  $('.your-class').slick({setting-name: setting-value
  });
});

4、完成后,你的 HTML 看起来应该像这样:

<html>
  <head>
  <title>My Now Amazing Webpage</title>
  <link rel="stylesheet" type="text/css" href="slick/slick.css"/>
  <link rel="stylesheet" type="text/css" href="slick/slick-theme.css"/>
  </head>
  <body>

  <div class="your-class"><div>your content</div><div>your content</div><div>your content</div>
  </div>

  <script type="text/javascript" src="//code.jquery.com/jquery-1.11.0.min.js"></script>
  <script type="text/javascript" src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
  <script type="text/javascript" src="slick/slick.min.js"></script>

  <script type="text/javascript">$(document).ready(function(){  $('.your-class').slick({    setting-name: setting-value  });});
  </script>

  </body>
</html>

5、数据属性设置【补充】

在 slick 1.5 中,您现在可以使用 data-slick 属性添加设置。您仍然需要调用 $(element).slick() 来初始化元素上的 slick。

<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>

Slick.js 重要 Demo

更多demo参考:https://kenwheeler.github.io/slick/

1、滑块同步(2个滑块组合使用)

$('.slider-for').slick({
  slidesToShow: 1,
  slidesToScroll: 1,
  arrows: false,
  fade: true,
  asNavFor: '.slider-nav'
});
$('.slider-nav').slick({
  slidesToShow: 3,
  slidesToScroll: 1,
  asNavFor: '.slider-for',
  dots: true,
  centerMode: true,
  focusOnSelect: true
});

2、中心模式

$('.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  }}
  ]
});

3、响应式(在不同的屏幕选择自己的模式)

$('.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  }}// You can unslick at a given breakpoint now by adding:// settings: "unslick"// instead of a settings object
  ]
});

Slick.js 重要属性

更多功能实现亦可参考:https://blog.51cto.com/u_15127510/4351224

官方属性:

accessibilitybooleantrueEnables tabbing and arrow key navigation
adaptiveHeightbooleanfalseEnables adaptive height for single slide horizontal carousels.
autoplaybooleanfalseEnables Autoplay
autoplaySpeedint(ms)3000Autoplay Speed in milliseconds
arrowsbooleantruePrev/Next Arrows
asNavForstringnullSet the slider to be the navigation of other slider (Class or ID Name)
appendArrowsstring$(element)Change where the navigation arrows are attached (Selector, htmlString, Array, Element, jQuery object)
appendDotsstring$(element)Change where the navigation dots are attached (Selector, htmlString, Array, Element, jQuery object)
prevArrowstring (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.
nextArrowstring (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.
centerModebooleanfalseEnables centered view with partial prev/next slides. Use with odd numbered slidesToShow counts.
centerPaddingstring’50px’Side padding when in center mode (px or %)
cssEasestring‘ease’CSS3 Animation Easing
customPagingfunctionn/aCustom paging templates. See source for use example.
dotsbooleanfalseShow dot indicators
dotsClassstring‘slick-dots’Class for slide indicator dots container
draggablebooleantrueEnable mouse dragging
fadebooleanfalseEnable fade
focusOnSelectbooleanfalseEnable focus on selected element (click)
easingstring‘linear’Add easing for jQuery animate. Use with easing libraries or default easing methods
edgeFrictioninteger0.15Resistance when swiping edges of non-infinite carousels
infinitebooleantrueInfinite loop sliding
initialSlideinteger0Slide to start on
lazyLoadstring‘ondemand’Set lazy loading technique. Accepts ‘ondemand’ or ‘progressive’
mobileFirstbooleanfalseResponsive settings use mobile first calculation
pauseOnFocusbooleantruePause Autoplay On Focus
pauseOnHoverbooleantruePause Autoplay On Hover
pauseOnDotsHoverbooleanfalsePause Autoplay when a dot is hovered
respondTostring‘window’Width that responsive object responds to. Can be ‘window’, ‘slider’ or ‘min’ (the smaller of the two)
responsiveobjectnoneObject containing breakpoints and settings objects (see demo). Enables settings sets at given screen width. Set settings to “unslick” instead of an object to disable slick at a given breakpoint.
rowsint1Setting this to more than 1 initializes grid mode. Use slidesPerRow to set how many slides should be in each row.
slideelementElement query to use as slide
slidesPerRowint1With grid mode intialized via the rows option, this sets how many slides are in each grid row. dver
slidesToShowint1# of slides to show
slidesToScrollint1# of slides to scroll
speedint(ms)300Slide/Fade animation speed
swipebooleantrueEnable swiping
swipeToSlidebooleanfalseAllow users to drag or swipe directly to a slide irrespective of slidesToScroll
touchMovebooleantrueEnable slide motion with touch
touchThresholdint5To advance slides, the user must swipe a length of (1/touchThreshold) * the width of the slider
useCSSbooleantrueEnable/Disable CSS Transitions
useTransformbooleantrueEnable/Disable CSS Transforms
variableWidthbooleanfalseVariable width slides
verticalbooleanfalseVertical slide mode
verticalSwipingbooleanfalseVertical swipe mode
rtlbooleanfalseChange the slider’s direction to become right-to-left
waitForAnimatebooleantrueIgnores requests to advance the slide while animating
zIndexnumber1000Set the zIndex values for slides, useful for IE9 and lower
滚动至顶部
扫描微信二维码联系我们 关闭