Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

scroll-carousel-react

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

scroll-carousel-react

Scroll carousel, a unique content slider that specially works on window scroll.

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

top language npm bundle size npm GitHub

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

NPM | Documentation | Demos

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
OptionTypeDefaultDescription
speednumber7The 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 slide
slideSelectorstringnullSelect 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 0
directionstring'rtl'Control direction left to right or right to left. Two possible option - ltr or rtl
onReady() => 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 class
elementTypestringdivTag, 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

License

The code and the documentation are released under the MIT License.

Keywords

FAQs

Package last updated on 30 Aug 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc