react-alice-carousel vs react-responsive-carousel vs react-slick
React 轮播组件
react-alice-carouselreact-responsive-carouselreact-slick类似的npm包:

React 轮播组件

这些库提供了用于在 React 应用程序中实现轮播和滑块功能的解决方案。它们各自具有独特的功能和设计理念,旨在帮助开发者轻松创建响应式和可定制的轮播效果。选择合适的库可以提高开发效率,并确保用户体验的流畅性和美观性。

npm下载趋势

3 年

GitHub Stars 排名

统计详情

npm包名称
下载量
Stars
大小
Issues
发布时间
License
react-alice-carousel085295.7 kB92 年前MIT
react-responsive-carousel02,677188 kB8-MIT
react-slick011,924775 kB4909 个月前MIT

功能对比: react-alice-carousel vs react-responsive-carousel vs react-slick

易用性

  • react-alice-carousel:

    react-alice-carousel 提供简单的 API 和直观的用法,适合快速集成和开发。它的文档清晰,示例丰富,帮助开发者快速上手。

  • react-responsive-carousel:

    react-responsive-carousel 也非常易于使用,提供了多种预设的样式和功能,开发者只需少量配置即可实现复杂的轮播效果。

  • react-slick:

    react-slick 的 API 设计较为复杂,功能丰富,适合需要高级自定义的开发者。虽然学习曲线稍陡,但一旦掌握,可以实现非常灵活的轮播效果。

响应式设计

  • react-alice-carousel:

    react-alice-carousel 支持响应式设计,能够根据屏幕尺寸自动调整轮播项的显示方式,适合移动设备和桌面设备。

  • react-responsive-carousel:

    react-responsive-carousel 专注于响应式布局,能够根据不同的设备和屏幕尺寸提供最佳的用户体验,确保轮播在各种设备上都能良好展示。

  • react-slick:

    react-slick 也支持响应式设计,允许开发者根据屏幕尺寸自定义显示的项目数量,提供灵活的展示方式。

自定义功能

  • react-alice-carousel:

    react-alice-carousel 提供丰富的自定义选项,包括动画效果、导航按钮和分页器等,允许开发者根据项目需求进行深度定制。

  • react-responsive-carousel:

    react-responsive-carousel 提供了一些内置的自定义选项,但相对较少,适合快速实现基本功能的项目。

  • react-slick:

    react-slick 提供强大的自定义功能,支持多种复杂的配置选项,如自定义导航、自动播放和切换效果,适合需要高度定制的项目。

性能

  • react-alice-carousel:

    react-alice-carousel 在性能方面表现良好,适合中小型项目,能够快速渲染和响应用户交互。

  • react-responsive-carousel:

    react-responsive-carousel 在处理大量图片时性能稳定,能够保持流畅的用户体验,适合需要展示大量内容的项目。

  • react-slick:

    react-slick 在处理复杂的轮播效果时性能优越,能够高效渲染多项内容,适合需要复杂交互和动画的项目。

社区支持

  • react-alice-carousel:

    react-alice-carousel 的社区相对较小,但文档和示例丰富,能够满足大部分开发需求。

  • react-responsive-carousel:

    react-responsive-carousel 拥有较大的用户基础和活跃的社区,提供了丰富的资源和支持,适合需要社区帮助的开发者。

  • react-slick:

    react-slick 拥有广泛的社区支持和大量的使用案例,开发者可以轻松找到解决方案和最佳实践,适合需要深入学习的项目。

如何选择: react-alice-carousel vs react-responsive-carousel vs react-slick

  • react-alice-carousel:

    选择 react-alice-carousel 如果你需要一个轻量级且易于使用的轮播组件,支持触摸和拖动手势,适合移动设备。它提供了丰富的自定义选项,适合需要高度可定制的项目。

  • react-responsive-carousel:

    选择 react-responsive-carousel 如果你需要一个响应式的轮播组件,支持多种布局和自适应设计,适合需要兼容多种设备的项目。它提供了多种内置的轮播样式和功能,易于使用。

  • react-slick:

    选择 react-slick 如果你需要一个功能强大的轮播组件,支持多种复杂的功能,如多项显示、无限循环和自定义导航。它适合需要高级功能和灵活性的项目。

react-alice-carousel的README

React Alice Carousel

npm version Build Status

React Alice Carousel is a React component for building content galleries, content rotators and any React carousels.

👉  Live demo (API): v2.x.x

👉  Previous version (API): v1.x.x

demo gif

demo gif

Features

  • Auto Height
  • Auto Play
  • Auto Width
  • Custom animation modes
  • Custom rendered slides
  • Infinite loop
  • Lazy loading
  • Mobile friendly
  • Multiple items in the slide
  • Responsive design
  • Stage padding
  • Show / hide anything (indicators, arrows, slides indexes)
  • Swipe to slide
  • Server side rendering friendly
  • Touch and Drag support
  • TypeScript

Installation

npm i react-alice-carousel

Style import

# CSS
@import "react-alice-carousel/lib/alice-carousel.css";
# SCSS
@import "react-alice-carousel/lib/scss/alice-carousel.scss";

Usage

import React from 'react';
import AliceCarousel from 'react-alice-carousel';
import 'react-alice-carousel/lib/alice-carousel.css';

const handleDragStart = (e) => e.preventDefault();

const items = [
	<img src="https://raw.githubusercontent.com/maxmarinich/react-alice-carousel/HEAD/path-to-img" onDragStart={handleDragStart} role="presentation" />,
	<img src="https://raw.githubusercontent.com/maxmarinich/react-alice-carousel/HEAD/path-to-img" onDragStart={handleDragStart} role="presentation" />,
	<img src="https://raw.githubusercontent.com/maxmarinich/react-alice-carousel/HEAD/path-to-img" onDragStart={handleDragStart} role="presentation" />,
];

const Gallery = () => <AliceCarousel mouseTracking items={items} />;

Options

  • activeIndex : Number, default 0 - Set carousel at the specified position.

  • animationDuration: Number, default 400 - Set duration of animation.

  • animationEasingFunction: String or Function, default ease - Property sets how an animation progresses through the duration of each cycle.

  • animationType: String(slide, fadeout), default slide - Set type of animation.

  • autoHeight: Boolean, default false - Set auto height mode.

  • autoWidth: Boolean, default false - Set auto width mode.

  • autoPlay: Boolean, default false - Set autoplay mode.

  • autoPlayControls: Boolean, default false - Show/hide play/pause buttons.

  • autoPlayDirection: String(ltr, rtl), default ltr - Set autoplay direction value.

  • autoPlayInterval: Number, default 400 - Set autoplay interval value.

  • autoPlayStrategy: String(default, action, all, none) - Set a strategy for autoplay mode

    • default - pause automatic playback on the hover
    • action - stop automatic playback if user action was detected
    • all - merge default && action strategies
    • none - ignore any user actions when the autoPlay property was specified
  • controlsStrategy: String (default, responsive, alternate or combined string "default,alternate") - Set a strategy for gallery controls.

    • default - use controls as is
    • alternate - show each dot for each slide
    • responsive - navigation will be hidden if the number of gallery elements is equal to the number of items in the slide.
  • disableButtonsControls: Boolean, default false - Disable buttons controls.

  • disableDotsControls: Boolean, default false - Disable dots controls.

  • disableSlideInfo: Boolean, default true - Disable information about current slide.

  • infinite: Boolean, default false - Set infinite mode.

  • innerWidth: Number, default 0 - Set a static value for a breakpoint(key) of the "responsive" property. For example, if you can't use 'window.innerWidth' during SSR.

  • items: Array, default undefined - Set gallery items, preferable to use this property instead of children.

  • keyboardNavigation: Boolean, default false - Enable keyboard navigation

    • ArrowLeft - go to the prev slide
    • ArrowRight - go to the next slide
    • Space - run/stop autoplay mode if autoPlay property is equal true
  • mouseTracking: Boolean, default false - Enable mouse drag animation. Consider the problem with links, see the example of using the <Link/> component below.

  • paddingLeft: Number, default 0 - Set the gallery offset from the left.

  • paddingRight: Number, default 0 - Set the gallery offset from the right.

  • renderKey: Number, default undefined - Auxiliary property, allows call the render method without changing the state inside the gallery instance.

  • responsive: Object, default undefined - The key is the breakpoint (default is the result of: () => window.innerWidth or innerWidth property if the last presented).

    • items - set number of items in the slide. Default: 1

    • itemsFit: one of (contain | fill | undefined) - defines, how item should fill the container according slide's width. Default: fill.

      If contain is specified, the gallery will use the value from the items property to determine the width of the element for each slide and fill in the empty space as needed.

          {
            0: {
                items: 1,
            },
            1024: {
                items: 3,
                itemsFit: 'contain',
            }
          }
    
  • syncStateOnPropsUpdate: Boolean, default true - Sync some props (like activeIndex) with carousel state while new props passed. This allows you to avoid resetting the carousel position while updating the props (e.g.: children or items).

  • swipeDelta: Number, default 20 - Set minimum distance to the start of the swiping (px).

  • swipeExtraPadding: Number, default 200 - Set maximum distance from initial place before swipe action will be stopped (px).

  • ssrSilentMode: Boolean, default true - Disable classnames modifiers for server side rendering.

  • touchTracking: Boolean, default true - Enable touch move animation.

  • touchMoveDefaultEvents: Boolean, default true - Enable touch move default events on swiping. If false was specified, this prevents vertical scrolling of the parent elements during the swipe.

  • onInitialized(e: EventObject): Function - Fired as callback after the gallery was created.

  • onResizeEvent(e: Event): Function, default shouldProcessResizeEvent method - Fired during the "resize" event to determine whether to call the event handler. Default method checks is the root element width has changed.

  • onResized(e: EventObject): Function - Fired as callback after the gallery was resized.

  • onUpdated(e: EventObject): Function - Fired as callback after updating the gallery props.

  • onSlideChange(e: EventObject): Function - Fired before the event object changes.

  • onSlideChanged(e: EventObject): Function - Fired after the event object was changed.

  • renderSlideInfo(e: SlideInfo): Rendering function - create a custom component.

  • renderDotsItem(e: DotsItem): Rendering function - create a custom component.

  • renderPrevButton({ isDisabled }): Rendering function - create a custom component.

  • renderNextButton({ isDisabled }): Rendering function - create a custom component.

  • renderPlayPauseButton({ isPlaying }): Rendering function - create a custom component.

Methods (Refs example)

  • slidePrev(e: Event) => void : Go to the prev slide.
  • slideNext(e: Event) => void : Go to the next slide.
  • slideTo(activeIndex?: number) => void : Go to the specified slide.

Components (Links example)

  • <Link /> : allows properly handle click and drag events when mouseTracking enabled, extends base HTMLAnchorElement
import React from 'react';
import AliceCarousel, { Link } from 'react-alice-carousel';
import 'react-alice-carousel/lib/alice-carousel.css';

const Gallery = () => {
  return (
    <AliceCarousel mouseTracking>
      <Link href="#">
        <img src="https://raw.githubusercontent.com/maxmarinich/react-alice-carousel/HEAD/path-to-image" />
      </Link>
    </AliceCarousel>
  );
};

Types

type EventObject = {
	item: number;
	slide: number;
	itemsInSlide: number;
	isPrevSlideDisabled: boolean;
	isNextSlideDisabled: boolean;
	type: EventType;
};

type SlideInfo = {
	item: number;
	itemsCount: number;
};

type DotsItem = {
	isActive: boolean;
	activeIndex: number;
};

enum EventType {
	ACTION = 'action', // used if a general user action (button click or swipe)
	INIT = 'init', // used if the initial event was triggered
	RESIZE = 'resize', // used if the gallery size was changed
	UPDATE = 'update', // used if the gallery was updated with props
}

CSS classes

.alice-carousel
	.alice-carousel__stage
	.alice-carousel__stage-item
	.alice-carousel__prev-btn
	.alice-carousel__prev-btn-item
	.alice-carousel__next-btn
	.alice-carousel__next-btn-item
	.alice-carousel__play-btn
	.alice-carousel__play-btn-item
	.alice-carousel__dots
	.alice-carousel__dots-item
	.alice-carousel__slide-info
	.alice-carousel__slide-info-item;

CSS modifiers

.alice-carousel.__ssr
	.alice-carousel__stage-item.__active
	.alice-carousel__stage-item.__cloned
	.alice-carousel__stage-item.__target
	.alice-carousel__next-btn-item.__inactive
	.alice-carousel__prev-btn-item.__inactive
	.alice-carousel__play-btn-item.__pause
	.alice-carousel__dots-item.__active
	.alice-carousel__dots-item.__custom
	.alice-carousel__slide-info-item.__separator;

Build the project locally

Clone

git clone https://github.com/maxmarinich/react-alice-carousel
cd react-alice-carousel

Run

npm ci
npm start

Test

npm test

License

MIT