项目作者: rafavth

项目描述 :
Lightweight vanilla javascript carousel.
高级语言: JavaScript
项目地址: git://github.com/rafavth/Desliza.git
创建时间: 2019-08-03T18:30:50Z
项目社区:https://github.com/rafavth/Desliza

开源协议:MIT License

下载


Desliza

Lightweight vanilla javascript carousel. Free for personal and commercial use.

Install

  1. <div class="desliza">
  2. <div>Content</div>
  3. <div>Content</div>
  4. <div>Content</div>
  5. <div>Content</div>
  6. </div>
  1. <script src="desliza.min.js"></script>
  2. <script>
  3. new Desliza();
  4. </script>

Options

  1. new Desliza({
  2. selector: '.desliza',
  3. duration: 180,
  4. easing: 'ease-out',
  5. items: 1,
  6. startIndex: 0,
  7. center : false,
  8. threshold: 20,
  9. draggable : true,
  10. dots : false,
  11. buttons : false,
  12. onInit: () => {},
  13. onChange: () => {},
  14. onAfterChange: () => {}
  15. });
Option Type Default Description
selector string ‘.desliza’ Carousel selector.
duration int 180 Transition duration.
easing string ‘ease-out’ CSS3 easing animation.
items int 1 Number of items in the viewport.
startIndex int 0 Starting item number.
center boolean false Center items.
threshold int 15 Dragging threshold (in px).
draggable boolean true Draggable items.
dots boolean false Current item indicators. (add desliza.css)
buttons boolean false Enable Next/Prev arrows. (add desliza.css)
onInit event {} Carousel initialization callback.
onChange event {} Before item change callback.
onAfterChange event {} After item change callback.

API

Method Description
next() Go to the next item.
  1. const dslz = new desliza();
  2. document.querySelector('.next').addEventListener('click', () => dslz.next());

Method Description
prev() Go to the previous item.
  1. const dslz = new desliza();
  2. document.querySelector('.prev').addEventListener('click', () => dslz.prev());

Method Description
moveTo(index) Go to a specific item.
  1. const dslz = new desliza();
  2. document.querySelector('.moveto').addEventListener('click', () => dslz.moveTo(2));

Browser support

Only modern browsers.