RepositoryTypeScript
ron0115

ron0115/react-smooth-scroll-hook

A React Hook for using smooth scroll in React Component

113sao
5fork
2issue
1lượt xem

🎯 Cuộn trang mượt mà trong React chỉ bằng vài dòng code

Hai hook useSmoothScroll và useScrollWatch thay thế hoàn hảo cho API scrollTo gốc của trình duyệt.

Đây là một thư viện React Hook viết bằng TypeScript, cung cấp useSmoothScroll để thực hiện cuộn trang mượt mà và useScrollWatch để theo dõi trạng thái cuộn. Dự án nhỏ gọn, không phụ thuộc bên thứ ba, phù hợp thay thế cho API scrollTo gốc.

✨ Điểm nổi bật

  • useSmoothScroll: Hook chính thực hiện cuộn trang mượt mà bằng requestAnimationFrame.
  • useScrollWatch: Theo dõi scrollTop, curIndex, curItem trong container cuộn.
  • Hỗ trợ hướng cuộn: Chọn x (ngang) hoặc y (dọc) qua tham số direction.
  • Tốc độ tùy chỉnh: Điều chỉnh speed (khoảng cách di chuyển mỗi khung hình), mặc định 100px.
  • Ngưỡng dừng: Tham số threshold xác định khoảng lỗi để kết thúc cuộn, mặc định 1px.
  • Hỗ trợ bộ chọn CSS: scrollTo chấp nhận selector (#id) hoặc số (khoảng cách px).
  • Không phụ thuộc bên thứ ba: Nhẹ và sạch, chỉ dựa trên API trình duyệt.
  • Tương thích toàn bộ trình duyệt: Dùng requestAnimationFrame tránh vấn đề tương thích.

💡 Vì sao đáng chú ý

Khác với cách dùng scrollTo gốc chỉ cuộn ngay lập tức, useSmoothScroll mang lại trải nghiệm cuộn mượt mà tự nhiên. Hai hook thiết kế riêng biệt: useSmoothScroll cho hành động cuộn và useScrollWatch cho theo dõi trạng thái, giúp tách biệt rõ ràng trách nhiệm. Thích hợp cho các ứng dụng React cần thanh cuộn mượt mà mà không muốn thêm thư viện nặng.


#React #SmoothScroll #ReactHooks #TypeScript #TiniX

Dự án tương tự

Khám phá các dự án và mô hình AI khác có sự tương đồng.

RepositoryTypeScript
juliencrn/usehooks-ts

React hook library, ready to use, written in Typescript.

7.9k
Nov 28, 2026
RepositoryTypeScript
JohannesKlauss/react-hotkeys-hook

React hook for using keyboard shortcuts in components.

3.5k
Dec 1, 2026
RepositoryTypeScript
imbhargav5/rooks

Over 800 k monthly downloads. Collection of awesome react hooks

3.4k
Nov 29, 2026
RepositoryTypeScript
react-hookz/web

React hooks done right, for browser and SSR.

2.2k
Nov 23, 2026
RepositoryTypeScript
quangtruong2003/SmoothScroll

Free smooth-scrolling utility for Windows 10/11 — velocity-based 120 Hz easing engine, per-app profiles, UWP support, zero telemetry. Built with Rust + Tauri.

117
Nov 22, 2026
RepositoryTypeScript
freeCodeCamp/freeCodeCamp

freeCodeCamp.org's open-source codebase and curriculum. Learn math, programming, and computer science for free.

459.9k
Dec 2, 2026
RepositoryJavaScript
codebucks27/Smooth-Scroll-Next.js

Implement smooth scrolling in Next.js with the help of Lenis scroll and add parallax effect using GSAP.

70
Oct 5, 2026
RepositoryJavaScript
react/react

The library for web and native user interfaces.

253.0k
Nov 30, 2026
RepositoryTypeScript
shadcn-ui/ui

Composable, accessible components with thoughtful defaults. Build your own component library with code you can customize, extend, and make your own.

130.0k
Dec 4, 2026