PW Carousel
Carousel with the following features:
- No dependencies
- Light: Just ~5Kb (without minifying or polyfills)
- Follows the progressive enhancement strategy:
- Works with just
html
- Works better with
html
andcss
- Works much better with
html
,css
andjs
- Works with just
- High performance: Use native scroll to move the elements.
- No need to wait for javascript to build the carousel.
- No styles or themes are provided with this package. You decide how the carousel must look.
- Support for touch devices
- Support for keyboard
- Build with ES6, so you may need a transpiler for old browser support
Install
Requirements:
- NPM or Yarn to install the package
Polyfills:
It's recommended to use the Scroll Behaviour polyfill to have better support for more browsers
npm install pw-carousel
Usage
HTML
Let's start with the following html code:
PreviousNext
CSS
Use css to define the carousel appearance:
JS
And finally use javascript for a complete experience:
; //Init the carouselconst slider = document; //Navigatedocument ; document ; //Autoplaysliderplayer;
Player
Use the property player
to access to the player in order to init a slideshow. Example:
//Start the slideshowsliderplayer; //Start the slideshow with 10 seconds to wait between slidessliderplayer; //Stopsliderplayer;
goto
Moves the slide to other position:
slider; //go to slider 3slider; //move one slider forward (slider 4)slider; //move two sliders backward (slider 2)slider; //go to first sliderslider; //go to the last sliderslider; //go to the current slider (refresh the position)
Demo
To run the demo, just clone this repository, enter in the directory and execute:
npm installnpm start
You should see something in http://localhost:8080/