An exquisite scroll-triggered carousel implemented with React

Scroll Carousel React

This is the react version of Scroll Carosel plugin, which is written in vanilla JavaScript.

View Demo View Github

Note: This carousel only operates in browser.

Install

npm
npm install scroll-carousel-react

Usages

With React JS
import React from 'react';
import ScrollCarousel from 'scroll-carousel-react';


const MyComponent = () => {
  return (
    <>
      <h1>This is my component page</h1>
      <p>Now i am showing my creation scroll carousel</p>
      <ScrollCarousel
        autoplay
        autoplaySpeed={8}
        speed={7}
        onReady={() => console.log('I am ready')}
      >
        {[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11].map((item) => (
          <div key={item} className='bg-blue-300/20 border-2 border-blue-300/70 rounded h-36 w-48'>
            {item}
          </div>
        ))}
      </ScrollCarousel>
    </>
  );
};

export default MyComponent;
With Next JS
  1. Make a component with any name ScrollCarouselComponent with the following code. This is a wrapper component.

components/ScrollCarouselComponent.js

// 'use client'; // For Next JS 13 app router


import React from 'react';
import ScrollCarousel from 'scroll-carousel-react';


const ScrollCarouselComponent = () => {
  return (
    <ScrollCarousel
      autoplay
      autoplaySpeed={8}
      speed={7}
      onReady={() => console.log('I am ready')}
    >
      {[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11].map((item) => (
        <div key={item} className='bg-blue-300/20 border-2 border-blue-300/70 rounded h-36 w-48'>
          {item}
        </div>
      ))}
    </ScrollCarousel>
  );
};

export default ScrollCarouselComponent;
  1. Import this component where you need it. But it should be dynamic import. This is because the next js tries to run the plugin in its server side. But as it is only available for client side. That's why it does not find window or document
// 'use client'; // For Next JS 13 app router

import React from 'react';

import dynamic from 'next/dynamic';

const ScrollCarousel = dynamic(() => import('@/components/ScrollCarouselComponent'), { ssr: false });

const MyComponent = () => {
  return (
    <div className='flex min-h-screen flex-col items-center justify-between p-24'>
      <div className='text-center'>
        <h2 className='text-4xl font-bold'>This is our about page</h2>
      </div>

      <ScrollCarousel />
    </div>
  );
};

export default MyComponent;

Props

  • All props are optional

OptionTypeDefaultDescriptionspeednumber7The value given is how fast you want to move on the scroll. It needs to be greater than 0.smartSpeedbooleanfalseTo calculate the speed of how fast or slow you are scrolling a website.marginnumber10To make gap between two slideslideSelectorstringnullSelect the slides with a class name you want to select for the carousel. Other elements will behave as simple.autoplaybooleanfalseThe option will allow the slides move automatically and still you will have the ability to handle sliding speed on scroll.autoplaySpeednumber5Control autoplay speed. It needs to be greater than 0directionstring'rtl'Control direction left to right or right to left. Two possible option - ltr or rtlonReady() => voidWhen the carousel is ready to perform its action, that time this event will be fired.onMove(progress: number) => voidWhen the carousel is on move (i,e at the time of scrolling, when autoplay enabled), the event will be fired continuously.onDestroy() => voidAt the time of destroy function, this event will be fired.classNamestringFor using with extra classelementTypestringdivTag, that will be used to create the carousel.scRef(ref: ScrollCarousel) => voidThis will give you an instance of scroll carousel. You can use it for method call.

For better documentaion, please have a look on the website of Scroll Carousel

GitHub

View Github

Related Posts

Recent Posts

ഇടുക്കിയിലെ മലയോര മേഖലകളിൽ രാത്രിയാത്ര നിരോധിച്ചു. രാത്രി ഏഴു മുതൽ രാവിലെ ആറു വരെയാണ് നിരോധനം

ഏന്തയാർ ഈസ്റ്റിൽ പ്രളയത്തിൽ തകർന്ന പാലത്തിന് പകരം പുതിയ പാലം നിർമ്മിക്കുവാൻ താത്ക്കാലിക പാലം പൊളിച്ച് നീക്കി

Explore the Investment Opportunities: A Comprehensive Guide to Different Types of Mutual Funds

Title: Understanding Mutual Funds: A Beginner's Guide to Investing

തീവ്രമഴ മുന്നറിയിപ്പിന്റെ പശ്ചാതലത്തിൽ സംസ്ഥാനം ജാഗ്രതയിൽ

250,000 അപേക്ഷകൾ വർദ്ധിച്ചതിനാൽ ട്രാൻസ്‌പോർട്ട് കമ്മീഷണർ പരിശോധന പുനരാരംഭിക്കും

ഏലക്കയിൽ കീടനാശിനി സാന്നിധ്യം; ആറര ലക്ഷത്തിലധികം ടിൻ അരവണ നശിപ്പിക്കാൻ ടെൻഡർ ക്ഷണിച്ച് ദേവസ്വം ബോർഡ്‌

ഭീമൻ പാറക്കഷണങ്ങൾ അടർന്ന് ദേശീയ പാതയിലേക്ക് വീഴുന്നത് പതിവാകുന്നു. കുട്ടിക്കാനത്തിനും മുണ്ടക്കയത്തിനുമിടയിൽ നിലനിൽക്കുന്നത് വൻ അപകട ഭീഷണി

ചക്രവാതച്ചുഴി:അതിശക്തമായ മഴ വരുന്നു

പ്ലസ് വൺ പ്രവേശനം. അക്ഷയയിൽ തിക്കി തിരക്കേണ്ട, നെറ്റിവിറ്റി/ജാതി തെളിയിക്കാൻ പത്താംതരം സർട്ടിഫിക്കറ്റ് മതി