jQuery中功能丰富 手风琴滑块

  • 源码大小:332.24KB
  • 所需积分:1积分
  • 源码编号:19JP-3255
  • 浏览次数:704次
  • 最后更新:2023年05月23日
  • 所属栏目:滑块
我要下载
加入收藏
本站默认解压密码:19jp.com 或 19jp_com

简介

一个jQuery插件,可以帮助您创建响应灵敏、触摸友好、支持视网膜的手风琴滑块,用于在页面上显示任何内容。

更多功能:

  • 图像延迟加载。
  • 动态内容加载:JSON或XML。
  • 允许在同一面板上放置多个图层。
  • 平滑过渡。
  • 寻呼子弹。
  • 支持Youtube/Vimeo/Sublime/HTML5视频。
  • 键盘和鼠标交互。
  • 可以与任何灯箱插件集成,如已知的FancyBox。
  • 支持深度链接。

目录:

  • 懒惰加载和视网膜支持
  • 图层类型和选项
  • 从JSON加载内容
  • 从XML加载内容
  • 智能视频
  • 插件选项
  • API方法
  • 事件

如何使用它:

1.安装Accordion Slider jQuery插件。

  1. <link rel="stylesheet" href="../dist/css/accordion-slider.min.css" />
  2. <script src="/path/to/cdn/jquery.min.js"></script>
  3. <script src="./dist/js/jquery.accordionSlider.min.js"></script>

2.在手风琴滑块上添加面板。

  1. <div id="example" class="accordion-slider">
  2. <div class="as-panels">
  3. <div class="as-panel">
  4. <img class="as-background" src="1.jpg" />
  5. </div>
  6. <div class="as-panel">
  7. <img class="as-background" src="2.jpg" />
  8. </div>
  9. <div class="as-panel">
  10. <img class="as-background" src="3.jpg" />
  11. </div>
  12. <div class="as-panel">
  13. <img class="as-background" src="4.jpg" />
  14. </div>
  15. <div class="as-panel">
  16. <img class="as-background" src="5.jpg" />
  17. </div>
  18. </div>
  19. </div>

3.初始化父容器上的插件,生成一个基本的手风琴滑块。

  1. $('#example').accordionSlider({
  2. // options here
  3. });

4.启用延迟加载和高分辨率/视网膜图像。

  1. <img class="as-background"
  2. src="./dist/css/images/blank.gif"
  3. data-src="/path/to/original/image.jpg"
  4. data-retina="/path/to/original/[email protected]" />

5.使用以下CSS类和HTML将多层添加到手风琴面板数据属性。

  • 打开时:只有当面板打开时,该层才可见。
  • 关闭时:只有当面板关闭时,层才会可见。
  • 黑色:黑色背景。
  • 白色:浅色背景。
  • 作为填充:在图层中添加10倍的填充。
  • 圆形:圆角。
  • 垂直:将图层的方向设置为垂直。
  • 背景打开时:打开面板时交换背景图像
  • 数据宽度:层的宽度。
  • 数据高度:层的高度。
  • 数据深度:Z索引CSS属性。
  • 数据位置:“topLeft”(默认值)、“topRight”、“bottomLeft”或“bottomRight”
  • 横向数据:固定值、百分比值或“中心”。
  • 垂直数据:与“水平数据”相同。
  • 数据显示转换:“左”、“右”、“上”或“下”。
  • 数据隐藏转换:与“数据显示转换”相同。
  • 数据显示偏移:向图层添加偏移。
  • 数据隐藏偏移:向图层添加偏移。
  • 数据显示持续时间:过渡的持续时间。
  • 数据隐藏持续时间:过渡的持续时间。
  • 数据显示延迟:过渡延迟。
  • 数据隐藏延迟:过渡延迟。
  1. <div class="as-panel">
  2. <a href="http://bqworks.com">
  3. <img class="as-background" src="../dist/css/images/blank.gif" data-src="https://source.unsplash.com/700x500/?summer" data-retina="https://source.unsplash.com/700x500/?summer"/>
  4. </a>
  5. <div class="as-layer as-closed as-white as-vertical panel-counter"
  6. data-position="bottomLeft" data-horizontal="8" data-vertical="8">
  7. Panel 2
  8. </div>
  9. <div class="as-layer"
  10. data-position="bottomLeft" data-horizontal="20" data-vertical="20" data-width="100%">
  11. <p class="as-layer as-opened as-white as-padding"
  12. data-position="bottomLeft"
  13. data-show-transition="left" data-hide-transition="up" data-show-delay="400" data-hide-delay="200">
  14. Lorem ipsum
  15. </p>
  16. <p class="as-layer as-opened as-black as-padding hide-small-screen"
  17. data-position="bottomLeft" data-horizontal="120"
  18. data-show-transition="left" data-hide-transition="up" data-show-delay="600" data-hide-delay="100">
  19. dolor sit amet
  20. </p>
  21. <p class="as-layer as-opened as-white as-padding hide-small-screen"
  22. data-position="bottomLeft" data-horizontal="245"
  23. data-show-transition="left" data-hide-transition="up" data-show-delay="800">
  24. consectetur adipisicing elit.
  25. </p>
  26. </div>
  27. </div>

6.从JSON加载内容。

  1. $('#example').accordionSlider({
  2. JSONSource: '/path/to/accordion.json',
  3. });
  1. // accordion.json
  2. {
  3. "accordion": {
  4. "panels": [
  5. {
  6. "background": {"source": "/path/to/1.jpg"},
  7. "backgroundRetina": {"source": "path/to/[email protected]"},
  8. "backgroundOpened": {"source": "path/to/alt1.jpg"},
  9. "backgroundOpenedRetina": {"source": "path/to/[email protected]"},
  10. "backgroundLink": {"address": "https://jqueryscript.net"},
  11. "layers": [
  12. {"content": "Panel 1", "style": "closed white padding panel-counter", "position": "bottomLeft", "horizontal": "8", "vertical": "8"},
  13. {"content": "Lorem ipsum dolor sit amet", "style": "opened black padding", "showTransition": "down", "hideTransition": "up", "horizontal": "20", "vertical": "20"}
  14. ]
  15. },
  16. //...
  17. ]
  18. }
  19. }

7.从XML加载内容。

  1. $('#example').accordionSlider({
  2. JSONSource: '/path/to/accordion.xml',
  3. });
  1. <!-- accordion.xml -->
  2. <accordion>
  3. <panel>
  4. <background>path/to/1.jpg</background>
  5. <backgroundRetina>path/to/[email protected]</backgroundRetina>
  6. <backgroundOpened>path/to/1.jpg</backgroundOpened>
  7. <backgroundOpenedRetina>path/to/[email protected]</backgroundOpenedRetina>
  8. <backgroundLink>https://jqueryscript.net/</backgroundLink>
  9. <layer vertical="8" horizontal="8" position="bottomLeft" style="closed white vertical panel-counter">Panel 1 </layer>
  10. <layer vertical="10%" horizontal="40" style="opened black padding" hideTransition="left" showTransition="left">Lorem ipsum dolor sit amet </layer>
  11. <layer vertical="22%" horizontal="40" style="opened white padding" hideTransition="left" showTransition="left" hideDelay="200" showDelay="200">consectetur adipisicing elit </layer>
  12. <layer vertical="34%" horizontal="40" style="opened black padding" hideTransition="left" showTransition="left" hideDelay="500" showDelay="400" width="350">sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. </layer>
  13. </panel>
  14. ...
  15. </accordion>

8.它还支持Youtube/Vimeo/Sublime/HTML5视频。

  1. <!-- Youtube -->
  2. <iframe class="as-video" src="https://www.youtube.com/embed/VIDEO-ID?enablejsapi=1&amp;wmode=opaque" width="500" height="350" frameborder="0" allowfullscreen></iframe>
  3.  
  4. <!-- Vimeo -->
  5. <iframe class="as-video" src="https://player.vimeo.com/video/VIDEO-ID?api=1" width="500" height="350" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
  6.  
  7. <!-- HTML5 Video -->
  8. <video class="as-video" poster="path/to/poster.jpg" width="500" height="350" controls="controls" preload="none">
  9. <source src="path/to/video.mp4" type="video/mp4"/>
  10. <source src="path/to/video.ogv" type="video/ogg"/>
  11. </video>
  12.  
  13. <!-- Video.js -->
  14. <div class="as-video" data-videojs-id="video1">
  15. <video id="video1" class="video-js vjs-default-skin" poster="path/to/poster.jpg" width="500" height="350" controls="controls" preload="none" data-setup="{}">
  16. <source src="path/to/video.mp4" type="video/mp4"/>
  17. <source src="path/to/video.ogv" type="video/ogg"/>
  18. </video>
  19. </div>
  20.  
  21. <!-- Sublime Video -->
  22. <video id="video2" class="as-video sublime" poster="path/to/poster.jpg" width="500" height="350" controls="controls" preload="none">
  23. <source src="path/to/video.mp4" type="video/mp4"/>
  24. <source src="path/to/video.ogv" type="video/ogg"/>
  25. </video>

9.完整的插件选项。

  1. $('#example').accordionSlider({
  2.  
  3. // width/height
  4. width: 800,
  5. height: 400,
  6.  
  7. // enable responsive layout
  8. responsive: true,
  9.  
  10. // 'auto' or 'custom'
  11. responsiveMode: 'auto',
  12.  
  13. // aspect ratio
  14. aspectRatio: -1,
  15.  
  16. // 'horizontal' or 'vertical'.
  17. orientation: 'horizontal',
  18.  
  19. // 0 for the first panel
  20. startPanel: -1,
  21.  
  22. // the size of the opened panel
  23. // fixed or percentage value
  24. openedPanelSize: 'max',
  25.  
  26. // max size of opened panel
  27. maxOpenedPanelSize: '80%',
  28.  
  29. // 'hover', 'click', or 'never'
  30. openPanelOn: 'hover',
  31.  
  32. // close the opened panels on mouse out
  33. closePanelsOnMouseOut: true,
  34.  
  35. // the delay in milliseconds between the movement of the mouse pointer and the opening of the panel
  36. mouseDelay: 200,
  37.  
  38. // the distance between consecutive panels
  39. panelDistance: 0,
  40.  
  41. // duration on ms
  42. openPanelDuration: 700,
  43. closePanelDuration: 700,
  44. pageScrollDuration: 500,
  45.  
  46. // easing function
  47. pageScrollEasing: 'swing',
  48.  
  49. /* e.g.
  50. {
  51. 960: {visiblePanels: 5},
  52. 800: {visiblePanels: 3, orientation: 'vertical', width: 600, height: 500},
  53. 650: {visiblePanels: 4},
  54. 500: {visiblePanels: 3, orientation: 'vertical', aspectRatio: 1.2}
  55. }/*
  56. breakpoints: null,
  57.  
  58. // visible panels
  59. visiblePanels: -1,
  60.  
  61. // 0 for the first page
  62. startPage: 0,
  63.  
  64. // adds shadow to the accordion slider
  65. shadow: true,
  66.  
  67. // determines if the panels will be shuffled/randomized
  68. shuffle: false,
  69.  
  70. // determines if the panels will be overlapped
  71. panelOverlap: true,
  72.  
  73. // autoplay options
  74. autoplay: true,
  75. autoplayDelay: 5000,
  76. autoplayDirection: 'normal', // 'normal' or 'backwards
  77. autoplayOnHover: 'pause', // 'pause', 'stop' or 'none'
  78.  
  79. // keyboard options
  80. keyboard: true,
  81. keyboardOnlyOnFocus: false,
  82. keyboardTarget: 'panel', // 'panel' or 'page',
  83.  
  84. // mousewheel options
  85. mouseWheel: true,
  86. mouseWheelSensitivity: 10,
  87. mouseWheelTarget: 'panel', // 'panel' or 'page'
  88.  
  89. // swap background options
  90. swapBackgroundDuration: 700,
  91. fadeOutBackground: false,
  92.  
  93. // touch swipe opitons
  94. touchSwipe: true,
  95. touchSwipeThreshold: 50,
  96.  
  97. // 'playVideo' or 'none'
  98. openPanelVideoAction: 'playVideo',
  99.  
  100. // 'pauseVideo' or 'stopVideo'
  101. closePanelVideoAction: 'pauseVideo',
  102.  
  103. // 'stopAutoplay' or 'none'
  104. playVideoAction: 'stopAutoplay',
  105.  
  106. // 'startAutoplay' or 'none'
  107. pauseVideoAction: 'none',
  108.  
  109. // 'startAutoplay', 'nextPanel', 'replayVideo' or 'none'
  110. endVideoAction: 'none',
  111.  
  112. // callback functions
  113. // or $('#example').on('callbackName', function(event) {})
  114. init: function() {},
  115. update: function() {},
  116. accordionMouseOver: function() {},
  117. accordionMouseOut: function() {},
  118. panelClick: function(index) {},
  119. panelMouseOver: function(index) {},
  120. panelMouseOut: function(index) {},
  121. panelOpen: function(index, previousIndex) {},
  122. panelsClose: function(previousIndex) {},
  123. pageScroll: function(index) {},
  124. panelOpenComplete: function(index) {},
  125. panelsCloseComplete: function(previousIndex) {},
  126. pageScrollComplete: function(index) {},
  127. breakpointReach: function(size, settings) {},
  128. videoPlay: function() {},
  129. videoPause: function() {},
  130. videoEnd: function() {},
  131.  
  132. });

10.API方法。

  1. // $('#example').accordionSlider('methodName', value);
  2. // or
  3. // var accordion = $('#example').data('accordionSlider');
  4. // accordion.methodName(value);
  5.  
  6. // Returns all the data of the panel at the specified index.
  7. accordion.getPanelAt(index);
  8.  
  9. // Returns the index of the current panel.
  10. accordion.getCurrentIndex();
  11.  
  12. // Returns the total number of panels.
  13. accordion.getTotalPanels();
  14.  
  15. // Opens the next panel.
  16. accordion.nextPanel();
  17.  
  18. // Opens the previous panel.
  19. accordion.previousPanel();
  20.  
  21. // Opens the panel at the specified index.
  22. accordion.openPanel(index);
  23.  
  24. // Closes all panels.
  25. accordion.closePanels();
  26.  
  27. // Gets the number of visible panels.
  28. accordion.getVisiblePanels();
  29.  
  30. // Gets the number of pages.
  31. accordion.getTotalPages();
  32.  
  33. // Gets the index of the page currently displayed.
  34. accordion.getCurrentPage();
  35.  
  36. // Scrolls to the specified page.
  37. accordion.gotoPage(index);
  38.  
  39. // Goes to the next page.
  40. accordion.nextPage();
  41.  
  42. // Goes to the previous page.
  43. accordion.previousPage();
  44.  
  45. // Destroy
  46. accordion.destroy();
  47.  
  48. // Updates the accordion
  49. accordion.update();
  50.  
  51. // Removes all panels
  52. accordion.removePanels();
  53.  
  54. // resize the accordion slider
  55. accordion.resize();

10.事件。

  1. // $('#example').on(eventType, callback);
  2. // $('#example').off(eventType);
  3.  
  4. $('#example').on('init', function(event) {
  5. // do something
  6. });
  7.  
  8. $('#example').on('update', function(event) {
  9. // do something
  10. });
  11.  
  12. $('#example').on('accordionMouseOver', function(event) {
  13. // do something
  14. });
  15.  
  16. $('#example').on('accordionMouseOut', function(event) {
  17. // do something
  18. });
  19.  
  20. $('#example').on('panelClick', function(event, index) {
  21. // do something
  22. });
  23.  
  24. $('#example').on('panelMouseOver', function(event, index) {
  25. // do something
  26. });
  27.  
  28. $('#example').on('panelMouseOut', function(index) {
  29. // do something
  30. });
  31.  
  32. $('#example').on('panelOpen', function(event, index, previousIndex) {
  33. // do something
  34. });
  35.  
  36. $('#example').on('panelsClose', function(event, previousIndex) {
  37. // do something
  38. });
  39.  
  40. $('#example').on('pageScroll', function(event, index) {
  41. // do something
  42. });
  43.  
  44. $('#example').on('panelOpenComplete', function(event, index) {
  45. // do something
  46. });
  47.  
  48. $('#example').on('panelsCloseComplete', function(event, previousIndex) {
  49. // do something
  50. });
  51.  
  52. $('#example').on('pageScrollComplete', function(event, index) {
  53. // do something
  54. });
  55.  
  56. $('#example').on('breakpointReach', function(event, size, settings) {
  57. // do something
  58. });
  59.  
  60. $('#example').on('videoPlay', function(event) {
  61. // do something
  62. });
  63.  
  64. $('#example').on('videoPause', function(event) {
  65. // do something
  66. });
  67.  
  68. $('#example').on('videoEnd', function(event) {
  69. // do something
  70. });

更新日志:

2022-12-16

  • 恢复触摸滑动模块中的代码更改

预览截图