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 🙏

© 2024 – Pkg Stats / Ryan Hefner

slider-controller

v1.0.0

Published

CSS scroll-snap slider with control options

Downloads

86

Readme

Slider Controller

The SliderController is a custom web component built using the LitElement library. It provides a slider functionality for a collection of SlideItem elements.

Installation

You can install the SliderController using npm.

npm install slider-controller

Then, you need to import the SliderController and SlideItem in your project.

import "slider-controller"
import "slide-item"

Usage

To use the SliderController, you need to include it in your HTML as a custom element. The SlideItem elements should be nested inside the SliderController.

<slider-controller>
  <slide-item>Slide 1</slide-item>
  <slide-item>Slide 2</slide-item>
  <slide-item>Slide 3</slide-item>
  <!-- Add more slide items as needed -->
</slider-controller>

Each SlideItem represents a single slide in the slider. You can put any content inside a SlideItem.

The SliderController automatically handles the scrolling behavior of the slides. It also emits custom events SLIDER_SCROLLING and SLIDER_SCROLLING_DONE which you can listen to for custom behavior.

Methods

| Method | Type | Description | | ---------- | --------- | ---------------------------- | | next() | method | Slides to next slide-item | | previous() | method | Slides to previous slide-item |

Getters

| Method | Type | Description | | ---------- | --------- | ---------------------------- | | currentIndex | getter | Gets the current index of the active slider | | totalItems | getter | Gets the total number of slide-items | | hasPrevious | getter | Is there a previous slide-item? Good for disabling buttons fx. | | hasNext | getter | Is there a next slide-item? Good for disabling buttons fx. |

Event Listeners

| Event | Type | Description | | ---------- | --------- | ---------------------------- | | SLIDER_SCROLLING | event | Fires on each DOM scroll event | | SLIDER_SCROLLING_DONE | event | Fires after scroll is done |

Cleanup

The SliderController automatically cleans up its event listeners when it is disconnected from the DOM. You don't need to manually remove the event listeners.

Note

The SliderController uses a debounced scroll and resize event to improve performance. The debounce delay is currently set to 300ms.

Styling

The SliderController component uses CSS variables for some of its styles, which you can override in your own CSS. Here's how you can do it:

  1. --slider-controller-gap: This variable controls the gap between the slides. You can set it to any valid CSS length value. For example, to set the gap to 20px, you would do:
slider-controller {
  --slider-controller-gap: 20px;
}
  1. --slider-controller-item-size: This variable controls the size of the slides. You can set it to any valid CSS length value. The default is auto meaning that the items retain their natural size. For example, to set the size to 200px, you would do:
slider-controller {
  --slider-controller-item-size: 200px;
}

Note that these variables should be set on the slider-controller element itself, not on the :host selector inside the slider-controller's CSS.

In addition to these variables, you can also apply any other CSS styles to the slider-controller element as you would with any other HTML element. However, keep in mind that due to the Shadow DOM, styles applied outside the slider-controller will not affect the internal elements of the slider-controller (like the .container div). If you need to style these internal elements, you would need to modify the slider-controller.css.ts file directly.