一个jQuery插件,可以帮助您创建响应灵敏、触摸友好、支持视网膜的手风琴滑块,用于在页面上显示任何内容。
1.安装Accordion Slider jQuery插件。
- <link rel="stylesheet" href="../dist/css/accordion-slider.min.css" />
- <script src="/path/to/cdn/jquery.min.js"></script>
- <script src="./dist/js/jquery.accordionSlider.min.js"></script>
2.在手风琴滑块上添加面板。
- <div id="example" class="accordion-slider">
- <div class="as-panels">
- <div class="as-panel">
- <img class="as-background" src="1.jpg" />
- </div>
- <div class="as-panel">
- <img class="as-background" src="2.jpg" />
- </div>
- <div class="as-panel">
- <img class="as-background" src="3.jpg" />
- </div>
- <div class="as-panel">
- <img class="as-background" src="4.jpg" />
- </div>
- <div class="as-panel">
- <img class="as-background" src="5.jpg" />
- </div>
- </div>
- </div>
3.初始化父容器上的插件,生成一个基本的手风琴滑块。
- $('#example').accordionSlider({
- // options here
- });
4.启用延迟加载和高分辨率/视网膜图像。
- <img class="as-background"
- src="./dist/css/images/blank.gif"
- data-src="/path/to/original/image.jpg"
- data-retina="/path/to/original/[email protected]" />
5.使用以下CSS类和HTML将多层添加到手风琴面板数据
属性。
- <div class="as-panel">
- <a href="http://bqworks.com">
- <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"/>
- </a>
- <div class="as-layer as-closed as-white as-vertical panel-counter"
- data-position="bottomLeft" data-horizontal="8" data-vertical="8">
- Panel 2
- </div>
- <div class="as-layer"
- data-position="bottomLeft" data-horizontal="20" data-vertical="20" data-width="100%">
- <p class="as-layer as-opened as-white as-padding"
- data-position="bottomLeft"
- data-show-transition="left" data-hide-transition="up" data-show-delay="400" data-hide-delay="200">
- Lorem ipsum
- </p>
- <p class="as-layer as-opened as-black as-padding hide-small-screen"
- data-position="bottomLeft" data-horizontal="120"
- data-show-transition="left" data-hide-transition="up" data-show-delay="600" data-hide-delay="100">
- dolor sit amet
- </p>
- <p class="as-layer as-opened as-white as-padding hide-small-screen"
- data-position="bottomLeft" data-horizontal="245"
- data-show-transition="left" data-hide-transition="up" data-show-delay="800">
- consectetur adipisicing elit.
- </p>
- </div>
- </div>
6.从JSON加载内容。
- $('#example').accordionSlider({
- JSONSource: '/path/to/accordion.json',
- });
- // accordion.json
- {
- "accordion": {
- "panels": [
- {
- "background": {"source": "/path/to/1.jpg"},
- "backgroundRetina": {"source": "path/to/[email protected]"},
- "backgroundOpened": {"source": "path/to/alt1.jpg"},
- "backgroundOpenedRetina": {"source": "path/to/[email protected]"},
- "backgroundLink": {"address": "https://jqueryscript.net"},
- "layers": [
- {"content": "Panel 1", "style": "closed white padding panel-counter", "position": "bottomLeft", "horizontal": "8", "vertical": "8"},
- {"content": "Lorem ipsum dolor sit amet", "style": "opened black padding", "showTransition": "down", "hideTransition": "up", "horizontal": "20", "vertical": "20"}
- ]
- },
- //...
- ]
- }
- }
7.从XML加载内容。
- $('#example').accordionSlider({
- JSONSource: '/path/to/accordion.xml',
- });
- <!-- accordion.xml -->
- <accordion>
- <panel>
- <background>path/to/1.jpg</background>
- <backgroundRetina>path/to/[email protected]</backgroundRetina>
- <backgroundOpened>path/to/1.jpg</backgroundOpened>
- <backgroundOpenedRetina>path/to/[email protected]</backgroundOpenedRetina>
- <backgroundLink>https://jqueryscript.net/</backgroundLink>
- <layer vertical="8" horizontal="8" position="bottomLeft" style="closed white vertical panel-counter">Panel 1 </layer>
- <layer vertical="10%" horizontal="40" style="opened black padding" hideTransition="left" showTransition="left">Lorem ipsum dolor sit amet </layer>
- <layer vertical="22%" horizontal="40" style="opened white padding" hideTransition="left" showTransition="left" hideDelay="200" showDelay="200">consectetur adipisicing elit </layer>
- <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>
- </panel>
- ...
- </accordion>
8.它还支持Youtube/Vimeo/Sublime/HTML5视频。
- <!-- Youtube -->
- <iframe class="as-video" src="https://www.youtube.com/embed/VIDEO-ID?enablejsapi=1&wmode=opaque" width="500" height="350" frameborder="0" allowfullscreen></iframe>
- <!-- Vimeo -->
- <iframe class="as-video" src="https://player.vimeo.com/video/VIDEO-ID?api=1" width="500" height="350" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
- <!-- HTML5 Video -->
- <video class="as-video" poster="path/to/poster.jpg" width="500" height="350" controls="controls" preload="none">
- <source src="path/to/video.mp4" type="video/mp4"/>
- <source src="path/to/video.ogv" type="video/ogg"/>
- </video>
- <!-- Video.js -->
- <div class="as-video" data-videojs-id="video1">
- <video id="video1" class="video-js vjs-default-skin" poster="path/to/poster.jpg" width="500" height="350" controls="controls" preload="none" data-setup="{}">
- <source src="path/to/video.mp4" type="video/mp4"/>
- <source src="path/to/video.ogv" type="video/ogg"/>
- </video>
- </div>
- <!-- Sublime Video -->
- <video id="video2" class="as-video sublime" poster="path/to/poster.jpg" width="500" height="350" controls="controls" preload="none">
- <source src="path/to/video.mp4" type="video/mp4"/>
- <source src="path/to/video.ogv" type="video/ogg"/>
- </video>
9.完整的插件选项。
- $('#example').accordionSlider({
- // width/height
- width: 800,
- height: 400,
- // enable responsive layout
- responsive: true,
- // 'auto' or 'custom'
- responsiveMode: 'auto',
- // aspect ratio
- aspectRatio: -1,
- // 'horizontal' or 'vertical'.
- orientation: 'horizontal',
- // 0 for the first panel
- startPanel: -1,
- // the size of the opened panel
- // fixed or percentage value
- openedPanelSize: 'max',
- // max size of opened panel
- maxOpenedPanelSize: '80%',
- // 'hover', 'click', or 'never'
- openPanelOn: 'hover',
- // close the opened panels on mouse out
- closePanelsOnMouseOut: true,
- // the delay in milliseconds between the movement of the mouse pointer and the opening of the panel
- mouseDelay: 200,
- // the distance between consecutive panels
- panelDistance: 0,
- // duration on ms
- openPanelDuration: 700,
- closePanelDuration: 700,
- pageScrollDuration: 500,
- // easing function
- pageScrollEasing: 'swing',
- /* e.g.
- {
- 960: {visiblePanels: 5},
- 800: {visiblePanels: 3, orientation: 'vertical', width: 600, height: 500},
- 650: {visiblePanels: 4},
- 500: {visiblePanels: 3, orientation: 'vertical', aspectRatio: 1.2}
- }/*
- breakpoints: null,
- // visible panels
- visiblePanels: -1,
- // 0 for the first page
- startPage: 0,
- // adds shadow to the accordion slider
- shadow: true,
- // determines if the panels will be shuffled/randomized
- shuffle: false,
- // determines if the panels will be overlapped
- panelOverlap: true,
- // autoplay options
- autoplay: true,
- autoplayDelay: 5000,
- autoplayDirection: 'normal', // 'normal' or 'backwards
- autoplayOnHover: 'pause', // 'pause', 'stop' or 'none'
- // keyboard options
- keyboard: true,
- keyboardOnlyOnFocus: false,
- keyboardTarget: 'panel', // 'panel' or 'page',
- // mousewheel options
- mouseWheel: true,
- mouseWheelSensitivity: 10,
- mouseWheelTarget: 'panel', // 'panel' or 'page'
- // swap background options
- swapBackgroundDuration: 700,
- fadeOutBackground: false,
- // touch swipe opitons
- touchSwipe: true,
- touchSwipeThreshold: 50,
- // 'playVideo' or 'none'
- openPanelVideoAction: 'playVideo',
- // 'pauseVideo' or 'stopVideo'
- closePanelVideoAction: 'pauseVideo',
- // 'stopAutoplay' or 'none'
- playVideoAction: 'stopAutoplay',
- // 'startAutoplay' or 'none'
- pauseVideoAction: 'none',
- // 'startAutoplay', 'nextPanel', 'replayVideo' or 'none'
- endVideoAction: 'none',
- // callback functions
- // or $('#example').on('callbackName', function(event) {})
- init: function() {},
- update: function() {},
- accordionMouseOver: function() {},
- accordionMouseOut: function() {},
- panelClick: function(index) {},
- panelMouseOver: function(index) {},
- panelMouseOut: function(index) {},
- panelOpen: function(index, previousIndex) {},
- panelsClose: function(previousIndex) {},
- pageScroll: function(index) {},
- panelOpenComplete: function(index) {},
- panelsCloseComplete: function(previousIndex) {},
- pageScrollComplete: function(index) {},
- breakpointReach: function(size, settings) {},
- videoPlay: function() {},
- videoPause: function() {},
- videoEnd: function() {},
- });
10.API方法。
- // $('#example').accordionSlider('methodName', value);
- // or
- // var accordion = $('#example').data('accordionSlider');
- // accordion.methodName(value);
- // Returns all the data of the panel at the specified index.
- accordion.getPanelAt(index);
- // Returns the index of the current panel.
- accordion.getCurrentIndex();
- // Returns the total number of panels.
- accordion.getTotalPanels();
- // Opens the next panel.
- accordion.nextPanel();
- // Opens the previous panel.
- accordion.previousPanel();
- // Opens the panel at the specified index.
- accordion.openPanel(index);
- // Closes all panels.
- accordion.closePanels();
- // Gets the number of visible panels.
- accordion.getVisiblePanels();
- // Gets the number of pages.
- accordion.getTotalPages();
- // Gets the index of the page currently displayed.
- accordion.getCurrentPage();
- // Scrolls to the specified page.
- accordion.gotoPage(index);
- // Goes to the next page.
- accordion.nextPage();
- // Goes to the previous page.
- accordion.previousPage();
- // Destroy
- accordion.destroy();
- // Updates the accordion
- accordion.update();
- // Removes all panels
- accordion.removePanels();
- // resize the accordion slider
- accordion.resize();
10.事件。
- // $('#example').on(eventType, callback);
- // $('#example').off(eventType);
- $('#example').on('init', function(event) {
- // do something
- });
- $('#example').on('update', function(event) {
- // do something
- });
- $('#example').on('accordionMouseOver', function(event) {
- // do something
- });
- $('#example').on('accordionMouseOut', function(event) {
- // do something
- });
- $('#example').on('panelClick', function(event, index) {
- // do something
- });
- $('#example').on('panelMouseOver', function(event, index) {
- // do something
- });
- $('#example').on('panelMouseOut', function(index) {
- // do something
- });
- $('#example').on('panelOpen', function(event, index, previousIndex) {
- // do something
- });
- $('#example').on('panelsClose', function(event, previousIndex) {
- // do something
- });
- $('#example').on('pageScroll', function(event, index) {
- // do something
- });
- $('#example').on('panelOpenComplete', function(event, index) {
- // do something
- });
- $('#example').on('panelsCloseComplete', function(event, previousIndex) {
- // do something
- });
- $('#example').on('pageScrollComplete', function(event, index) {
- // do something
- });
- $('#example').on('breakpointReach', function(event, size, settings) {
- // do something
- });
- $('#example').on('videoPlay', function(event) {
- // do something
- });
- $('#example').on('videoPause', function(event) {
- // do something
- });
- $('#example').on('videoEnd', function(event) {
- // do something
- });
2022-12-16