1.0.0 • Published 5 years ago

marvina-carousel-react v1.0.0

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

Marvina Carousel React

React integration for Marvina Carousel.

NPM

npm install –-save-dev marvina-carousel-react

Yarn

yarn add marvina-carousel-react --dev

Installation

import React from 'react';
import * as Marvina from 'marvina-carousel-react';

export default class App extends React.Component {
    render() {
        return(
            <div>
                <Marvina.Solo>                
                    <Marvina.Element>
                        <img src="img1.jpg" />
                    </Marvina.Element>
                    <Marvina.Element>
                        <img src="img2.jpg" />
                    </Marvina.Element>
                    <Marvina.Element>
                        <img src="img3.jpg" />
                    </Marvina.Element>
                    <Marvina.Element>
                        <img src="img4.jpg" />
                    </Marvina.Element>
                    <Marvina.Element>
                        <img src="img5.jpg" />
                    </Marvina.Element>
                </Marvina.Solo>
            </div>
        );
    }
}

If you want to slide carousel as group, you can use Group component, instead of Solo;

	render() {
        return(
            <div>
                <Marvina.Group>                
                    // ...
                </Marvina.Group>
            </div>
        );
    }

Add the css file.

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

Configuration

Options

OptionTypeDefaultDescription
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)
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.

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.
    componentDidMount() {
        this.carosuel.el.addEventListener('change', () => {
            console.log('changes');
        });
    }

    render() {
        return(
            <div>
                <Marvina.Group ref={node => this.carousel = node}>                
                    // ...
                </Marvina.Group>
            </div>
        );
    }

Methods

MethodParamsReturnDescription
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 React is provided under the MIT License.