mateCarousel is a lightweight carousel with a simple API. It transform class element into slides and give you the control of it, using a config object and some API commands to use on the go.
With this carousel, you can set autoplay, configure buttons, bullet-menu to chose between slides and a lot more. The way this API was developed let you chose from using the built-in solutions or handle the situations by yourself.
Oh! There is no default theme, which means the CSS part is up to you. And that’s a good thing!
How does it work?
mateCarousel iterates over elements of a DOM class. Once you call the library passing the class as an argument, we organize your carousel and leave it ready to shine! To make it, we use the translateX property. First element will have its value as 0%, second one as 100%, third one as 200% and so on.
For example, this code:
When you pass “inner” as an argument to mateCarousel…
… it will become that:
The config object
The second argument you can pass (but don’t feel obligated) is a config object. Some values are required to enable functionality, such as bullet-menu and after&before buttons:
Attention please! CSS must have:
The container block must have set overflow as “hidden” to achieve the carousel effect. And also, I advice you to set position to relative of fixed, but it depends on each case.
The class used to expose the elements to the Carousel must have position absolute, left: 0, top: 0, and should be nice to add some transition effect, such as “transform 300ms ease”.
At this moment, that class must as well have width and height set to 100%. I am working on it, so we could show more than one element per view, each time. Contributions are welcome.
when working with the bullet-menu, it’s wise to set the display as “inline”.
don’t forget to work with the “active” menu to get beautiful results on the bullets. It was set to highlight the active bullet.
That was the CSS I used to make the example in this page:
Ok. Now, how can I use the API?
Supposing that you captured a class elements which are inside the same container, now you start playing with your JavaScript:
But this way, it will have no buttons and no autoplay, and that’s no good. So, here you have some ways. First, is setting your carousel before running it, which I recommend.
or
But what if you want to set up it on the go? There are a bunch of options:
And there are more things in the API that you can use to implement your features:
carousel.goToPosition(n): go to the desired index. Be careful, do not use a number bigger than your class length.
carousel.next() and carousel.before(): go to the next slide. Useful to build your own buttons.
carousel.getIndex(): returns the current index displayed. You can do useful stuff with this output.
carousel.config(): returns the current config object. Set things on the go.