1.0.6 • Published 5 years ago

marvina-carousel v1.0.6

Weekly downloads
10
License
MIT
Repository
github
Last release
5 years ago

Marvina Carousel

Image Carousel for web and mobile browsers.\ For more information you can take a look at the demos: Demo 1, Demo 2, Demo 3.

NPM

npm install --save-dev marvina-carousel 

Yarn

yarn add marvina-carousel --dev

Installation

You can simply import Carousel class and create a new object with it.

import Carousel from 'marvina-carousel';

const carousel = new Carousel({
    el: '#carousel'
});

You can also add the script file into your html.

<script src="/node_modules/marvina-carousel/dist/js/marvina-carousel.min.js"></script>
<script>
var carousel = new MarvinaCarousel({
    el: '#carousel'
});
</script>

Add the css file.

<link rel="stylesheet" href="/node_modules/marvina-carousel/dist/css/marvina-carousel.min.css" />

Insert carousel elements into the container element.

<div id="carousel">
    <div class="mc-carousel-element">Image-1</div>
    <div class="mc-carousel-element">Image-2</div>
    <div class="mc-carousel-element">Image-3</div>
</div>

Configuration

Options

OptionTypeDefaultDescription
elstring | HTMLElement*nullContainer element.
timingstring"ease"Specifies the speed curve of an animation. Takes all the values CSS3 can take. (like ease, linear, cubic-bezier, step)
durationnumber800Defines how long an animation should take to complete one cycle. (as milliseconds)
groupbooleantrueSpecifies grouping type of the carousel elements.
minImagenumber1Minimum carousel element number that the carousel displays at once.
maxImagenumber1Maximum carousel element number that the carousel displays at once.
minWidthnumbernullSpecifies min width of an carousel element. (as pixel)
maxWidthnumbernullSpecifies max width of an carousel element. (as pixel)
heightnumbernullSets height value according to width. (as percent)
spacenumber0Specifies the space between the carousel elements. (as pixel)
touchMovebooleantrueEnables slide transitive with touch.
listbooleantrueDisplays a list at the bottom of the carousel.
asListstring | HTMLUListElement | HTMLOListElement*nullDeclares the given list as the carousel list.
arrowsbooleantrueDisplays right and left arrows to change the index.
asPrevArrowstring | HTMLElement*nullDeclares the given element as the prev arrow.
asNextArrowstring | HTMLElement*nullDeclares the given element as the next arrow.
autoPlaybooleanfalseEnables auto play of slides.
autoPlaySpeednumber5000Sets auto play interval. (as milliseconds)

*: You can give an HTML element or a CSS selector (like #carousel, .container > div:first-child)

As List

You can convert an HTML list element to a carousel list that shows the current index and works as a pager.

  • It can be a ul or ol element.
  • It can be placed anywhere in the body.
  • List is updated when the current index is changed.
  • Assigns mc-active class to list element that holds the current index.
// html
<div id="carousel">
    <div class="mc-carousel-element">Image-1</div>
    <div class="mc-carousel-element">Image-2</div>
    <div class="mc-carousel-element">Image-3</div>
</div>
<ul id="list">
    <li>1</li>
    <li>2</li>
    <li>3</li>
</ul>

// script
var carousel = new MarvinaCarousel({
    el: '#carousel',
    list: false,
    asList: '#list'
});

Events

EventDescription
changeFires when index changes.
totalIndexFires when total number of indexes change.
touchStartFires when touching starts.
touchEndFires when touching ends.
playFires when autoplay starts.
stopFires when autoplay stops.
destroyFires when the carousel is destroyed.
import Carousel from 'marvina-carousel';

const carousel = new Carousel({
    el: '#carousel'
});

carousel.el.addEventListener('touchStart', () => {
    console.log('touching starts');
});

carousel.el.addEventListener('touchEnd', () => {
    console.log('touching ends');
});

Methods

MethodParamsReturnDescription
addel: string | HTMLElement* index: numbervoidAdds a new element to the carousel.
addFirstel: string | HTMLElement*voidAdds a new element to the head of the carousel.
addLastel: string | HTMLElement*voidAdds a new element to the last of the carousel.
removeindex: numbervoidRemoves the element at the specified index from the carousel.
removeFirstvoidRemoves the first element from the carousel.
removeLastvoidRemoves the last element from the carousel.
prevPromise\Triggers previous image. Returns false if the carousel is in animation.
nextPromise\Triggers next image. Returns false if the carousel is in animation.
playvoidStarts autoplay.
stopvoidStops autoplay.
togglevoidToggles autoplay.
destroyvoidDestroys the carousel.
getIndexnumberReturns index.
setIndexindex: numberPromise\Sets index and animates the carousel. Returns false if the carousel is in animation.
getTotalnumberReturns total number of carousel elements.
getTotalIndexnumberReturns total index.
getTimingstringReturns timing value.
setTimingtiming: stringvoidSets timing value.
getDurationnumberReturns duration.
setDurationduration: numbervoidSets duration.
getAutoPlaySpeednumberReturns auto play speed.
setAutoPlaySpeedspeed: numbervoidSets auto play speed.

*: You can give an HTML element or a CSS selector (like #carousel, .container > div:first-child)

IE Support

IE 10 is not supported and patches to fix problems will not be accepted.

License

Marvina Carousel is provided under the MIT License.

Related Projects

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago