@reuse-sh/carousel

中文文档
0.1.0发布于 2026/11/02MITTypeScriptES Module零依赖构建来源已验证

A carousel built on native scrolling, with mouse dragging, grouping, repeat, and autoplay.

原始使用文档
文档目录6 节
  1. Principles
  2. Install
  3. Browser
  4. React
  5. Documentation
  6. License

@reuse-sh/carousel

A carousel that keeps native touch and trackpad scrolling with CSS snap. It adds mouse dragging, grouping, RTL, synchronized carousels, optional repeat, and autoplay.

Principles

These are the rules the code keeps. An adaptation on any framework keeps them too.

  • Let the browser scroll. Touch and trackpads scroll natively with CSS scroll snap, and every move from code is a scroll too.
  • Never let a drag click. A mouse drag, or the mouse press that stops a moving strip, never opens the link under it. An ordinary click still works, and touch stays native.
  • Drag like a trackpad. A released mouse drag keeps its speed and glides to the slide nearest where it would stop, never past a slide that asks to stop. Past either end it stretches and springs back.
  • Repeat without clones. The loop moves the original slides, so ids, links and buttons stay unique, and it turns on only when the slides can cover the viewport.
  • Let autoplay wait for people. Autoplay pauses for hover, focus, dragging, hidden pages, offscreen strips and reduced motion.
  • Keep keys local. Arrow keys act only inside the focused strip and swap sides in right-to-left layouts.
  • Put back what it moved. Destroy cancels timers and restores the styles, transforms and listeners it added.

Install

npm install @reuse-sh/carousel

Browser

import { createCarousel } from "@reuse-sh/carousel";
import "@reuse-sh/carousel/styles.css";

const viewport = document.querySelector("[data-carousel]");
const carousel = createCarousel(viewport, {
  align: "center",
  loop: true,
});
nextButton.addEventListener("click", () => carousel.next());
carousel.subscribe((state) => {
  counter.textContent = String(state.index + 1);
});

React

import { useCarousel } from "@reuse-sh/carousel/react";
import "@reuse-sh/carousel/styles.css";

function Gallery({ children }) {
  const { ref, carousel } = useCarousel({ loop: true });
  return <>
    <div ref={ref} className="re-carousel">
      {children}
    </div>
    <button onClick={() => carousel?.next()}>Next</button>
  </>;
}

Documentation

License

MIT

版本与发布记录

@reuse-sh/carousel 共发布 6 个版本,首次发布于 2026/11/02;过去 12 个月发布了 6 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.1.0latest2026/11/021 天前
0.0.42026/11/021 天前
0.0.32026/11/021 天前
0.0.22026/11/021 天前
0.0.12026/11/021 天前
0.0.0-stage2026/11/021 天前

关于 @reuse-sh/carousel 的常见问题

@reuse-sh/carousel 是什么?

基于本机滚动的旋转木马,具有鼠标拖动、分组、重复和自动播放功能。

如何安装 @reuse-sh/carousel?

在项目目录运行 npm install @reuse-sh/carousel,或使用 pnpm add / yarn add / bun add。

@reuse-sh/carousel 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@reuse-sh/carousel 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@reuse-sh/carousel 可以商用吗?

@reuse-sh/carousel 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@reuse-sh/carousel 还在维护吗?

最新版本 0.1.0 发布于 2026/11/02(1 天前);至今共发布 6 个版本,其中过去 12 个月发布了 6 个;首次发布于 2026/11/02。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。