Beautiful, easy to use, scroll triggered carousel.

Carousel

Open source

npm package

Responsive

It is meant to be utilized in mobile web apps and mobile websites. It is responsive by default. No need of manual control.

Easy to use

Scroll carousel has two ways of initialization which make it easier to use. If you have only knowledge of HTML, you can use this.

Library agnostic

It is significantly smaller and faster because of vanilla Javascript. It doesn’t need any JavaScript libraries like jQuery.

Typescript support

Scroll carousel is fully typed. Make sure you have a environment with typescript setup. Now just import and initialize. BOOM!!

Lightweight

Our structure provides excellent compression. Oh yes, it weighs only ~8kb (~2kb gzipped) with every functionality included.

Getting Started

Installation

Download

Javascript

CDN

CSS

                
                  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/scroll-carousel@1.2.7/dist/scroll.carousel.min.css" />
                
              

Javascript

                
                  <script src="https://cdn.jsdelivr.net/npm/scroll-carousel@1.2.7/dist/scroll.carousel.min.js"></script>
                
              

Package managers

npm

                
                  npm i scroll-carousel
                
              

Import JS

                
                  import ScrollCarousel from 'scroll-carousel';
                
              

Import CSS

                
                  @import 'node_modules/scroll-carousel/dist/scroll.carousel.min.css';
                
              

Demos

Basic Example

HTML

                    
                      <div class="my-carousel">
                          <div class="my-slide"></div>
                          <div class="my-slide"></div>
                          <div class="my-slide"></div>
                      </div>
                    
                  

Javascript

                    
                      new ScrollCarousel(".my-carousel");
                    
                  

Autoplay Example

HTML

                    
                      <div class="my-carousel">
                          <div class="my-slide"></div>
                          <div class="my-slide"></div>
                          <div class="my-slide"></div>
                      </div>
                    
                  

Javascript

                    
                      new ScrollCarousel(".my-carousel", {
                          autoplay: true
                      });
                    
                  

Direction Example

HTML

                    
                      <div class="my-carousel">
                          <div class="my-slide"></div>
                          <div class="my-slide"></div>
                          <div class="my-slide"></div>
                      </div>
                    
                  

Javascript

                    
                      new ScrollCarousel(".my-carousel", {
                          smartSpeed: true,
                          direction: 'ltr'
                      });
                    
                  

Slide Selector Example

HTML

                    
                      <div class="my-carousel">
                          <div class="my-element"></div>
                          <div class="my-slide"></div>
                          <div class="my-slide"></div>
                          <div class="my-slide"></div>
                          <div class="my-element"></div>
                      </div>
                    
                  

Javascript

                    
                      new ScrollCarousel(".my-carousel", {
                          slideSelector: '.my-slide'
                      });
                    
                  

API

Options

autoplay
Type: Boolean Default: false

The option will allow the slides move automatically and still you will have the ability to handle sliding speed on scroll.

autoplaySpeed
Type: Number Default: 5

Control autoplay speed. It needs to be greater than 0.

speed
Type: Number Default: 7

The value given is actually how fast you want to move on scroll. It needs to be greater than 0.

smartSpeed
Type: Boolean Default: false

It will give carousel movement speed depending on your scroll speed(how fast or slow you are scrolling).

direction
Type: String Default: rtl

Control direction left to right or right to left. Two possible option - 'ltr' or 'rtl'

slideSelector
Type: String Default: null

Select slide with class name which you want to select for carousel. Other element will behave as simple.

margin
Type: Number Default: 10

To make gap between slides.

Methods

destroy()

Remove ScrollCarousel functionality completely. destroy will return the element back to its pre-initialized state.

reinit()

This will initialize your carousel after destroy with previous options and returned the ScrollCarousel instance.

HTML

                          
                            <button id="button">Destroy</button>

                            <div class="my-carousel">
                                <div class="my-slide"></div>
                                <div class="my-slide"></div>
                                <div class="my-slide"></div>
                                <div class="my-slide"></div>
                                <div class="my-slide"></div>
                                <div class="my-slide"></div>
                                <div class="my-slide"></div>
                            </div>
                          
                        

Javascript

                          
                            let scrollCarousel = new ScrollCarousel(".my-carousel", {
                                speed: 8,
                                smartSpeed: true,
                                autoplay: true
                            });

                            document.querySelector('#button').addEventListener('click', function () {
                                if (scrollCarousel.isActive) {
                                  scrollCarousel.destroy();
                                } else {
                                  scrollCarousel = scrollCarousel.reinit();
                                }
                            });
                          
                        

Events

Scroll Carousel offers events in key areas of the code. This gives you the ability to listen for any changes and perform your own actions.

0%

ready

                          
                            let scrollCarousel = new ScrollCarousel(".my-carousel", {
                                speed: 8,
                                smartSpeed: true,
                                autoplay: true,
                                on: {
                                  ready: function () {
                                    console.log("Be ready");
                                  }
                                }
                            });
                          
                        

destroy

                          
                            let scrollCarousel = new ScrollCarousel(".my-carousel", {
                                speed: 8,
                                smartSpeed: true,
                                autoplay: true,
                                on: {
                                  destroy: function () {
                                    console.log("Destroyed");
                                  }
                                }
                            });
                          
                        

move

                          
                            let scrollCarousel = new ScrollCarousel(".my-carousel", {
                                speed: 8,
                                smartSpeed: true,
                                autoplay: true,
                                on: {
                                  move: function (progressPercent) {
                                    console.log("Scrolling", progressPercent);
                                  }
                                }
                            });