SimpleSlider
Simple responsive slider created in pure javascript.
Browsers support: All modern browsers, Internet Explorer 10+
Version
1.9.0
Installation
npm
Install the package & import files
npm install simpleslider-js
;;
CDN
Include files using CDN.
https://unpkg.com/simpleslider-js@1.9.0/dist/simpleSlider.min.js
https://unpkg.com/simpleslider-js@1.9.0/dist/simpleSlider.min.css
Github
You can also download files from Github and attach them manually to your project.
Note: On production use files (JS and CSS) only from dist/ folder.
Usage
Include files
See the section above.
Create HTML layout
<!-- First slide --> <!-- Any HTML content --> <!-- Second slide --> <!-- Any HTML content --> <!-- Third slide --> <!-- Any HTML content --> <!--Pagination (Not required)--> <!-- Buttons (Not required) -->
Initialize the module
<script> '.simple-slider-first';</script>
API
Example
new SimpleSlider(container, options)
- container - string (required), selector of slider container
- options - object (optional), slider options
You can initialize more than one slider per page.
<script> // Default options '.simple-slider-first'; // User options '.simple-slider-second' speed: 600 autoplay: false class: wrapper: 'slider-wrapper' { console; } ; // SlidesPerView example '.simple-slider-third' slidesPerView: 768: 2 // 2 slides for viewport >= 768px 1024: 3 // 3 slides for viewport >= 1024px ; // Access to other slider functions and properties var slider = '.simple-slider-third'; console;</script>
Options
Option | Type | Default value | Description |
---|---|---|---|
speed | number | 600 | Transition duration in ms |
delay | number | 5000 | Delay between transitions in ms (autoplay) |
enableDrag | boolean | true | Enable drag option |
autoplay | boolean | false | Slider autoplay |
loop | boolean | true | Slider loop |
slidesPerView | object | 1 | The number of slides to be shown [Read more below] |
class:wrapper | string | 'slider-wrapper' | Wrapper class |
class:slide | string | 'slider-slide' | Slide class |
class:buttons | string | 'slider-btn' | Buttons class |
class:pagination | string | 'slider-pagination' | Pagination class |
class:paginationItem | string | 'pagination-bullet' | Pagination bullet class |
onInit | function | - | Function called after slider initialization |
onChange | function | - | Function called when the slide change start |
Other functions and properties
.attachEvents()
- Attach all events
.detachEvents()
- Detach all events
.nextSlide()
- Go to the next slide
.prevSlide()
- Go to the previous slide
.index
- Get current slide index
.wrapper
- Slider wrapper
.container
- Slider container
.buttons
- Slider buttons
.slides
- List of slides
.slidesWithClones
- List of slides with clones
.paginationBullets
- List of pagination bullets
Comments
slidesPerView
- Number of slides can't be bigger than the amount of slides in the slider.