微小 SEO友好旋转木马jQuery插件 jCarouselLite

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

简介

一个轻量级的jQuery插件,用于从任何元素(如HTML列表或HTML5选择器)创建支持触摸和SEO友好的转盘。它很容易安装,并且可以根据您的需要随时进行自定义。

这个旋转木马插件是画廊、产品页面、内容密集的网站等的绝佳选择。对于任何想要在他们设计的任何网站上创建一个很棒的旋转木马的网页设计师来说,这都是一个很好的选择。

如何使用它:

1.要开始,请在jQuery之后包含jCarouselLite插件的文件。

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

2.将您的内容添加到转盘幻灯片中。这个旋转木马插件支持大多数类型的内容,如文本、图像、DIV等。

  1. <div class="carousel">
  2. <ul>
  3. <li>
  4. Slide 1
  5. </li>
  6. <li>
  7. Slide 2
  8. </li>
  9. <li>
  10. Slide 3
  11. </li>
  12. ...
  13. </ul>
  14. </div>

3.向转盘添加上一个/下一个按钮或分页链接。

  1. <button type="button" class="prev">&lt;</button>
  2. <button type="button" class="next">&gt;</button>
  3.  
  4. <!-- OR -->
  5. <div class="nav">
  6. <button type="button">1</button>
  7. <button type="button">2</button>
  8. <button type="button">3</button>
  9. ...
  10. </div>

4.隐藏溢出的内容。

  1. .carousel {
  2. overflow: hidden;
  3. }

5.初始化插件并完成。

  1. $('.carousel').jCarouselLite({
  2. btnNext: '.next',
  3. btnPrev: '.prev'
  4. });
  5.  
  6. // OR
  7. $('.carousel').jCarouselLite({
  8. btnGo: $('div.nav').find('button'),
  9. });

6.在转盘上启用鼠标滚轮事件。需要jQuery鼠标滚轮插件。

  1. <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-mousewheel/3.1.13/jquery.mousewheel.min.js"></script>
  1. $('.carousel').jCarouselLite({
  2. btnNext: '.next',
  3. btnPrev: '.prev',
  4. mouseWheel: true,
  5. });

7.可用于自定义转盘的插件选项。

  1. $('.carousel').jCarouselLite({
  2.  
  3. // container selector
  4. containerSelector: 'ul',
  5.  
  6. // item selector
  7. itemSelector: 'li',
  8.  
  9. // navigation selectors
  10. btnPrev: null,
  11. btnNext: null,
  12.  
  13. // array (or jQuery object) of elements
  14. btnGo: null,
  15.  
  16. // selector (or jQuery object) indicating the containing element for pagination navigation.
  17. autoPager: null,
  18.  
  19. // disabled class
  20. btnDisabledClass: 'disabled',
  21.  
  22. // class applied to the active slide and btnGo element
  23. activeClass: 'active',
  24.  
  25. // class applied to the btnGo elements corresponding to the visible slides
  26. visibleClass: 'vis',
  27.  
  28. // enable mousewheel support
  29. mouseWheel: false,
  30.  
  31. // animation speed
  32. speed: 200,
  33.  
  34. // additional easing functions
  35. easing: null,
  36.  
  37. // milliseconds between scrolls
  38. timeout: 4000,
  39.  
  40. // true to enable auto scrolling;
  41. // number to auto-scroll by different number at a time than that of scroll option
  42. auto: false,
  43.  
  44. // true to enable changing direction of auto scrolling when user clicks prev or next button
  45. directional: false,
  46.  
  47. // number of times before autoscrolling will stop.
  48. // (if circular is false, won't iterate more than number of items)
  49. autoStop: false,
  50.  
  51. // pause scrolling on hover
  52. pause: true,
  53.  
  54. // vertical layout
  55. vertical: false,
  56.  
  57. // continue scrolling when reach the last item
  58. circular: true,
  59.  
  60. // the number to be visible at a given time.
  61. visible: 3,
  62.  
  63. // index of item to show initially in the first position
  64. start: 0,
  65.  
  66. // number of items to scroll at a time
  67. scroll: 1,
  68.  
  69. // whether to set initial styles on the carousel elements. See readme for info
  70. autoCSS: true,
  71.  
  72. // whether the dimensions should change on resize
  73. responsive: false,
  74.  
  75. // whether to set width of <li>s (and left/top of <ul>) based on width of <div>
  76. autoWidth: false,
  77.  
  78. // touch options
  79. swipe: true,
  80. swipeThresholds: {
  81. x: 80,
  82. y: 40,
  83. time: 150
  84. },
  85.  
  86. // whether to prevent vertical scrolling of the document window when swiping
  87. preventTouchWindowScroll: true,
  88.  
  89. });

8.回调函数。

  1. $('.carousel').jCarouselLite({
  2.  
  3. // The function can take 2 arguments:
  4. // 1. The merged options object
  5. // 2. A jQuery object containing the <li> items in the carousel
  6. // If the function returns `false`, the plugin will skip all the carousel magic for that carousel div
  7. init: function() {},
  8.  
  9. // called once the first slide is hit
  10. first: null,
  11.  
  12. // called once the last slide is hit
  13. last: null,
  14.  
  15. // called before each transition starts
  16. beforeStart: null,
  17.  
  18. // called after each transition ends
  19. afterEnd: null
  20.  
  21. });

9.API方法。

  1. // pause
  2. $('.carousel').trigger('pauseCarousel');
  3.  
  4. // resume
  5. $('.carousel').trigger('resumeCarousel');
  6.  
  7. // stop
  8. $('.carousel').trigger('stopCarousel');
  9.  
  10. // refresh
  11. $('.carousel').trigger('refreshCarousel', '[all]')
  12.  
  13. // destroy
  14. $('.carousel').trigger('endCarousel');
  15.  
  16. // goto the next slide
  17. $('div.carousel').trigger('go');
  18.  
  19. // goto a specific slide
  20. $('.carousel').trigger('go', 3);
  21.  
  22. // goto a specific slide relative to the currently active item
  23. $('.carousel').trigger('go', '+=2');
  24. $('.carousel').trigger('go', '-=2');

预览截图