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

@fylgja/snap-slider

v2.1.0

Published

A CSS-powered slider/carousel, enhanced with JavaScript for improved functionality and accessibility

Readme

Fylgja - Snap Slider

NPM version License Netlify Status

A CSS-powered slider/carousel, enhanced with JavaScript for improved functionality and accessibility.

The Snap Slider is available as a Custom Element (the primary and recommended way) or as an AlpineJS component.

Installation

The Snap Slider can be integrated into your project via NPM or by using a CDN.

NPM Installation

Install the package from NPM:

npm install @fylgja/snap-slider

CDN Integration

Alternatively, you can include the script directly in your HTML using a <script> tag.

For the Custom Element:

<script defer src="https://unpkg.com/@fylgja/snap-slider/dist/custom-element/cdn.min.js"></script>

For the AlpineJS version:

<script defer src="https://unpkg.com/@fylgja/snap-slider/dist/alpine/cdn.min.js"></script>

Usage

The Snap Slider can be used as a Custom Element or as an AlpineJS component.

Custom Element (Recommended)

Import the custom element into your project:

import '@fylgja/snap-slider/custom-element';

Then, use the <snap-slider> element in your HTML. A [data-track] child element is required to contain the slides.

<snap-slider>
    <div data-track>
        <!-- Your slides go here -->
    </div>
</snap-slider>

AlpineJS Component

To use the AlpineJS version, import the component and register it with Alpine:

import Alpine from 'alpinejs';
import snapSlider from '@fylgja/snap-slider/alpine';

window.Alpine = Alpine;

Alpine.plugin(snapSlider);
Alpine.start();

Then, apply the x-snap-slider directive to your slider element.

<div x-data x-snap-slider>
    <div data-track>
        <!-- Your slides go here -->
    </div>
</div>

Configuration

The snap-slider supports the following data attributes for configuration:

| Data Attribute | Description | Default | | ----------------------------- | -------------------------------------------------------------------------- | ------------- | | data-track | Required. Identifies the container for the slider's slides. | | | data-next | Designates a button to navigate to the next slide. | | | data-prev | Designates a button to navigate to the previous slide. | | | data-pager | Designates the container for pagination markers. | | | data-auto-pager | Automatically generates pagination markers. | false | | data-group-pager | Groups pager markers based on the number of visible slides. | false | | data-slide-label-sepparator | Customizes the separator in the aria-label for slides (e.g., "1 of 12"). | of | | data-pager-class | Sets custom classes for the pager container. | snap-pager | | data-marker-class | Sets custom classes for the pager markers. | snap-marker |

AlpineJS Configuration

For the AlpineJS version, boolean options like auto-pager and group-pager are passed as modifiers to the x-snap-slider directive:

<div x-data x-snap-slider.auto-pager.group-pager>
    ...
</div>

Other data attributes can be applied directly to the element as usual.

Pager

You can add a pager to your slider in two ways:

1. Auto Pager

The easiest way to add a pager is by using the data-auto-pager attribute (or x-snap-slider.auto-pager for AlpineJS). This will automatically generate a pager for you.

By default, the pager is inserted after the [data-track] element. You can customize its location by adding an empty [data-pager] container anywhere inside the slider element.

2. Custom Pager

For more control, you can create a custom pager. Each slide must have a unique ID, and each pager marker must link to a slide's ID using href="#slide-id" or data-target-id="slide-id".

Group Pager

When multiple slides are visible at once, you can use the data-group-pager attribute (or x-snap-slider.group-pager for AlpineJS) to group the pager markers. This will only show one marker for each visible group of slides.

JavaScript API

You can interact with the slider programmatically using the following methods and events.

Methods

First, get the SnapSlider instance:

For the Custom Element:

const snapSliderElement = document.querySelector('snap-slider');
const snapSliderInstance = snapSliderElement.slider;

For the AlpineJS component:

const sliderEl = document.querySelector('[x-snap-slider]');
const snapSliderInstance = sliderEl.snapSlider;

| Method | Description | | ----------------- | ------------------------------------------------------------------------------- | | init() | Initializes the slider. This is called automatically. | | destroy() | Removes all event listeners and observers. | | refreshSlides() | Re-initializes the slider, useful when slides are added or removed dynamically. |

Events

The slider dispatches a slideChange event on the slider element whenever the in-view slides change.

const sliderEl = document.querySelector('snap-slider'); // Or '[x-snap-slider]'
sliderEl.addEventListener('slideChange', (event) => {
    console.log(event.detail);
});

The event.detail object contains the following properties:

| Property | Description | | ------------------- | ------------------------------------------------------- | | inViewSlides | An array of the slides currently in view. | | totalInViewSlides | The total number of slides in view. | | firstInViewSlide | The first slide in view. | | lastInViewSlide | The last slide in view. | | isAtStart | A boolean indicating if the slider is at the beginning. | | isAtEnd | A boolean indicating if the slider is at the end. | | hasNoOverflow | A boolean indicating if all slides are visible at once. |