1.0.1 • Published 5 years ago

tidy-carousel v1.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

**Tidy carousel** Build Status

This is a simple UI widget mobile-friendly, responsive built in vanilla javascript (es2015+) for modern browsers. Tidy carousel is inspired by a card deck as multiple slides stack together and based on an event an element is picked transforming its x-axis using percentage. Tidy carousel is also highly configurable (See config having features such as mouse drag, swipe, pager, infinite sliding and more.

**Installation**

Using npm:

> npm install tidy-carousel

Using yarn:

> yarn add tidy-carousel

Using unpkg:

<script type="text/javascript" src="https://unpkg.com/tidy-carousel/tidy-carousel.min.js"></script>

**Configuration.**

**Option****Type****Default****Description**
durationNumber500The duration of the slide.
nameStringnullThis option should be used when intializing multiple instances. ** *Note:** The name given must match with the attr(s) used for instance's controller/pager (data-for={name}) and also for the container (data-name={name}).
easingString'ease'The rate of the animation's change over time. Accepts the pre-defined values "linear", "ease", "ease-in", "ease-out", and "ease-in-out", or a custom "cubic-bezier" value like "cubic-bezier(0.42, 0, 0.58, 1)"
containerString/Node'.tidy__carousel'This is the wrapper of the slides, witch can be neither the node element or a selector as a string.
delayNumber500This is the delay in between each slide. Useful if auto is set to true.
autoBooleantrueThis makes the carousel loop without an event.
auto.directionString'left'This opts specifies in wich direction the carousel should slide. The only possible values can be 'right' or 'left'
swipeBooleantrueThis option (if true) will enable touch event for mobile devices.
dragBooleantrueThis option (if true) will enable the user to drag the slide.
startAtNumber0This option is the index of the first slide.
slidesArraynullIt should be an array of objects representing the slides.
slidesi.htmlStringIt should be a html element as a string e.g: <div class="my_slide">Content</div>. The element will be inserted into the DOM using element.insertadjacentelement method.
slidesi.srcStringIt should be the source of the image. *Note:**** This option is an alternative for slides[i].node.
slidesi.altString[]It should be the alternative for the image. **Note:** This option will only work if you set slides[i].src.
slidesi.beforeAnimation(element, index)FunctionA function that is invoked before the slide occurs.
slidesi.afterAnimation(element, index)FunctionA function that is invoked After the slide occurs. If present, it must return a promise e.g: afterAnimation: (element, index) => { return new Promise((success, reject) => { setTimeout(() => { doSomething(); success()}, 500)})}
pagerBooleanfalseThis option if true, the carousel will look for an <ul></ul> element with attr data-carousel-pagerand will generate a pager at the bottom of the carousel. ** Note:** If name opts is set, add the attribute data-for={name} to the uldata-carousel-pager.
pager.containerString/DOM nodeThe container of the pages. If available carousel will generate the pages within this element.
infiniteBooleantrueIf set to true, the carousel will loop infinitely.
controllersString/DOM node'data-carousel-controller'Can be set to a node element or a selector as a string. Each controller must have the attribute data-carousel-controller="left or right". ** Note:** If name opts is set, add the attribute data-for={name} to each controller.
beforeAnimation(elem, index)FunctionA function that is invoked before the slide occurs.
afterAnimation(elem, index)FunctionA function that is invoked After the slide occurs. If present, it must return a promise e.g: afterAnimation: (element, index) => { return new Promise((success, reject) => { setTimeout(() => { doSomething(); success()}, 500)})} **Note:** This function is only invoked if the slides is not set to an array of slides.

Usage.

For more examples visit http://tidy-carousel.com/documentation/examples.

Html

<div class="tidyCarousel">
  <!-- Here goes all the slides -->
  <div class="tidyCarousel-slide"><div class="first"></div></div>
  <div class="tidyCarousel-slide"><div class="second"></div></div>
  <div class="tidyCarousel-slide"><div class="third"></div></div>

</div>
<button type="button" carousel-controller="left">
  <
</button>
<button type="button" carousel-controller="right">
  >
</button>
<ul class="tidyCarousel-pager" carousel-pager>
</ul>

Javascript.


 import TidyCarousel from 'tidy-carousel';

 const config = {}; // See: https://github.com/dorultan/tidy-carousel#configuration.
 const carousel = new Carousel(config);

Issues

For any issues please open a new issue with an appropriate label, write a simple headline and a comment containing the following:

  • Your browser (e.g: Chrome v.54)
  • Your installation method (e.g: yarn v.1.19.1)
  • Details (Such as your markup or any useful info.)

Contribution

Any contribution to this project **is very appreciated**. In order to contribute to this project, make a pull request using development branch.

License

This work is licensed under MIT License .