Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Fast and tiny React carousel

License

NotificationsYou must be signed in to change notification settings

pietile/pietile-carousel

Repository files navigation

npm versionminzipped bundle size

React carousel based onFramer Motion without repaints and simple in use.

Features

  • Doesn't require to specify items dimensions (pure css solution)
  • Relies on translates for movements (zero paints)
  • Arbitrary number of visible items
  • Сyclicality

Installation

Using yarn

yarn add pietile-carousel

or using npm

npm install -S pietile-carousel

Pietile Carouseldepends onFramer Motion which is a peer dependency so be sure that it's installed in you project (if not then install it usingyarn add framer-motion ornpm install -S framer-motion)

Usage

Every item is wrapped in container where it can layout it's content. The size of container depends on the size of carousel and amount of visible items. You can use any styling system you want to set styles. Get ref and use moveLeft/moveRight/moveTo methods for scroll.

Example

importReactfrom'react';import{PietileCarousel}from'pietile-carousel';functionApp(){constcarouselStyle={width:150,height:100,};constitemStyle={width:'100%',height:'100%',};return(<PietileCarouselstyle={carouselStyle}><divstyle={{ ...itemStyle,backgroundColor:'red'}}/><divstyle={{ ...itemStyle,backgroundColor:'orange'}}/><divstyle={{ ...itemStyle,backgroundColor:'yellow'}}/></PietileCarousel>);}

API

Properties

namedescriptiontypedefault
autoplayIntervalHow often autoplay happens (0 to disable)number0
childrenComponents rendered in carousel (required)Node-
classNameCSS classstring-
countAmount of visible itemsnumber1
draggableAllow dragbooleantrue
marginMargin between itemsnumber0
styleStyle objectObject-
onChangeCallback when index changesFunction-

Methods

namedescription
slideNext()Scroll to next slide
slidePrev()Scroll to previous slide
slideTo(index)Scroll to index

Note

Carousel protects nesting links (a-tag's) from undesirable behavior (link click is being processed when the user starts dragging and release the mouse outside of the carousel) by callingpreventDefault for the correspondentclick event. If you are handling clicks manually you can checkdefaultPrevented when processing your event.

License

Pietile Carousel is MIT License.


[8]ページ先頭

©2009-2025 Movatter.jp