Giter Club home page Giter Club logo

react-spring-3d-carousel's Introduction

react-spring-3d-carousel

A 3D Carousel component for images built with React and utilizing react-spring for controlling slide transitions. It's primarily meant to be controlled via the goToSlide prop but I also provided a showNavigation prop if you don't feel like making your own navigation.

This should go without saying, but if you use this component make sure to test it for performance and compatability with your target browsers.

Example

Edit react-spring-3d-carousel-basic-example

Installation and usage

Install it via npm:

npm i react-spring-3d-carousel

or yarn:

yarn add react-spring-3d-carousel

Then import the Carousel component like so :

import Carousel from 'react-spring-3d-carousel';

The only thing this component needs to run is an array of slides, which are objects with a unique key property and a content property containing an image instance :

const slides = [
  {
    key: uuidv4(),
    content: <img src="https://picsum.photos/800/800/?random" alt="1" />
  },
  {
    key: uuidv4(),
    content: <img src="https://picsum.photos/800/800/?random" alt="2" />
  },
  {
    key: uuidv4(),
    content: <img src="https://picsum.photos/600/800/?random" alt="3" />
  },
  {
    key: uuidv4(),
    content: <img src="https://picsum.photos/800/500/?random" alt="4" />
  },
  {
    key: uuidv4(),
    content: <img src="https://picsum.photos/800/800/?random" alt="5" />
  },
  {
    key: uuidv4(),
    content: <img src="https://picsum.photos/500/800/?random" alt="6" />
  },
  {
    key: uuidv4(),
    content: <img src="https://picsum.photos/800/600/?random" alt="7" />
  },
  {
    key: uuidv4(),
    content: <img src="https://picsum.photos/800/800/?random" alt="8" />
  }
];

...

<Carousel slides={slides} />

And you're all set. You can also use props for better control of how the carousel looks and behaves:

Props

Name Default value Description
slides --- An array containing elements of the form { key, content, onClick? } where key holds any unique value and content holds a reference to a JSX <img /> to be displayed. onClick is an optional property that may be used to pass a callback method which will be invoked when the slide is clicked.
goToSlide null Setting this prop will cause the carousel to animate towards the provided index in the slides array. If showNavigation is set to false this prop is how you're expected to control the carousel.
goToSlideDelay 200 The amount of milliseconds to delay each slide before moving to the next one while animating towards the index provided in goToSlide.
offsetRadius 2 Number of carousel elements to display to the sides of the current slide, this value is clamped between 1 and Math.floor(slides.length/2), and defaults to 2 when it's possible (if there are enough slide elements).
animationConfig { tension: 120, friction: 14 } A config object passed to the slides' Spring element to control the nature of their animation, for more information check the react-spring docs.

react-spring-3d-carousel's People

Contributors

gutiguy avatar dependabot[bot] avatar kindeep avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.