npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@lifarl/react-scroll-snap-slider

v3.0.0-alpha

Published

A performant React Slider / Carousel Component with CSS Scroll Snapping, Intersection Observer and Accessibility.

Readme

react-scroll-snap-slider

A performant React Slider / Carousel Component with CSS Scroll Snapping, Intersection Observer and Accessibility.

npm bundle size npm version NPM

Have a look at the Demo for the different variations. demo

Installation

yarn add @lifarl/react-scroll-snap-slider

Note: From v3.0.0, this library ships plain CSS (no styled-components). There are no styling peer dependencies.

Usage


import { Slider } from '@lifarl/react-scroll-snap-slider';

<Slider>
  <div>Foo</div>
  <div>Bar</div>
  <div>Baz</div>
</Slider>

See also examples in App.tsx

Styling / CSS

  • Import once at app entry: import '@lifarl/react-scroll-snap-slider/styles.css'.
  • All classes are prefixed with .scs- to avoid global leaks.
  • Theming uses CSS variables set on any parent (or the component root):
    • --scs-gap (default 8px)
    • --scs-arrow-bg (default #fff)
    • --scs-arrow-padding (default 0.5em)
    • --scs-arrow-radius (default 4px)
    • --scs-arrow-color (default #676767)
    • --scs-arrow-size (default 22px)
    • --scs-scroll-behavior (default smooth)
    • --scs-snap-type (default x mandatory) — set to x proximity to reduce snap sensitivity on Chrome/Android
    • --scs-snap-stop (default normal) — set to always to prevent skipping multiple slides per gesture
    • --scs-touch-action (default pan-x) — adjust to auto if you need vertical gestures over the slider
    • --scs-overscroll-behavior (default auto) — set to contain to prevent scroll chaining to parent

Slots and class overrides are supported via classes on the Slider component:

<Slider
  classes={{
    root: 'my-carousel',
    slider: 'my-slider',
    list: 'my-list',
    slide: 'my-slide',
    nav: 'my-nav',
    navPrev: 'my-nav-prev',
    navNext: 'my-nav-next',
    arrow: 'my-arrow',
  }}
>
  {...}
</Slider>

Intersection Observer

Firing tracking events on css based sliders can be done with the intersection observer. Pass onSlideVisible to the Carousel and it will fire when a slide enters the viewport without triggering a rerender.

Props

onSlideVisible?: (index: number) => void // Callback that is triggered when a slide gets visible by a threshold of 0.5
renderCustomArrow?: ({
  direction,
  ref,
  onClick,
}: CustomArrowProps) => JSX.Element // In case you want to use your own arrow design and logic
slidesPerPageSettings?: SlidesPerPageSettings // optionally for setting fixed amounts of slides for different viewports (min-width: 512px / 753px / 1232px)
slideWidth?: number // optionally for setting a fixed slide width
onScrollStart?: () => void // callback that triggers at the beginning of the scroll event
onScrollEnd?: (index: number) => void // callback that triggers at the end of the scroll event
children: React.ReactNode // put your slides here :)
className?: string // root class override
classes?: Partial<{
  root: string
  slider: string
  list: string
  slide: string
  nav: string
  navPrev: string
  navNext: string
  arrow: string
}>

Browser Support

This lib does not include scroll snap polyfills to support older browsers like ie11. You would need to add them yourself. For more information see here.

Tuning Snap Feel (Android/Chrome)

Mobile browsers implement different scroll-snap heuristics. If the slider feels “too sensitive” on Android/Chrome (small flicks advance a slide, or gestures skip multiple slides), you can tune behavior via CSS variables:

/* Apply to your slider root */
.my-slider {
  /* Reduce sensitivity */
  --scs-snap-type: x mandatory;  /* default */

  /* Avoid skipping multiple slides */
  --scs-snap-stop: always;

  /* Optional axis + scroll chaining controls */
  --scs-touch-action: pan-x;           /* default */
  --scs-overscroll-behavior: contain;  /* keep scroll inside slider */
}

Usage:

<Slider classes={{ root: 'my-slider' }}>
  {...}
</Slider>

Notes:

  • x proximity only snaps when near a snap point, which typically reduces accidental snaps on Android compared to mandatory.
  • scroll-snap-stop: always ensures the browser does not skip over intermediate slides during a fast flick.
  • If you need vertical page scrolling to take priority when swiping over the slider, set --scs-touch-action: auto on the slider root.