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 🙏

© 2026 – Pkg Stats / Ryan Hefner

modular-slider

v1.0.3

Published

A zero dependency slider with a modular approach, written in Typescript

Readme

Modular Slider

A dependency-free slider with NO DOM manipulations, written in Typescript

Check out the demos here

Modular Slider aims to deliver just what you want, while using the best of EcmaScript goodies. Here are some of its features:

  • :label: written in Typescript and ESM
  • :zap: relies on promises, async/await and event listeners
  • :art: modular architecture - optimized for tree-shaking, weighs nothing in your final build
  • :fire: absolutely no DOM manipulations - no removing, adding or cloning nodes, just class and style attribute tweaks
  • :rocket: works perfectly with any frontend framework - does not break down v-dom thanks to no DOM manipulations
  • :boom: supports SSR - tested in Nuxt.js & SvelteKit

This package ships as an esm module only.

Architecture

Modular Slider consists of base classes and plugins:

Base classes

Base classes provide basic functionalities of the slider. Their names are PascalCase. currently, there are 3 mixins:

  • Carousel - provides methods for a carousel slider (with a loop)
  • NoLoop - provides methods for a basic slider
  • SliderBase - an abstract class, not a ready-to-use slider, provides basic methods for creating your own slider

Plugins

Plugins are functions that enrich your slider with non-critical features. Their names are all camelCase. Here are the currently available plugins:

  • swipeHandler - provides event handling - compulsory if you want to drag the slider with mouse/touch
  • buttons - adds next/previous slide buttons
  • pagination - adds pagination
  • autoplay - adds autoplay
  • duplicate - useful for Carousels, makes sure that there are no fewer sliders than the set number of slides per view + 2 which is required for the loop
  • lazyLoading - enables lazy loading images in the slider, loads image's srcset when the slide is in view

Usage

First of all download the package:

$ npm i modular-slider
$ pnpm i modular-slider
$ yarn add modular-slider
$ bun install modular-slider
$ deno install npm:modular-slider

Once you've done that, take a look at an example setup:

  1. Add markup:
  • outer container with id and .MS-wrapper class
  • inner container with .MS-con class
  • some slides inside - no classes required
<section class="your-slider-class MS-wrapper">
  <ul id="your-slider-id" class="MS-con">
    <li>1</li>
    <li>2</li>
    <li>3</li>
    <li>4</li>
    <li>5</li>
    <li>6</li>
  </ul>
</section>

<!-- add buttons for the purpose of the example -->
<section class="slider-buttons">
  <button id="prev">prev</button>
  <button id="next">next</button>
</section>
  1. import css from "modular-slider/dist/modular-slider.css" and follow one of the available options. This example uses the default option
@import "modular-slider/dist/modular-slider.css";

.your-slider-class {
  --number-of-slides: 6; // the number of the slides, total
  --slides-per-view: 2; // the number of how many slides are displayed at once
  // your css...
}
  1. Add js
import { Carousel, swipeHandler, lazyLoading } from "modular-slider";

new Carousel({
   container: "your-slider-id", // id of the inner container
   initialSlide: 1, // optional, default is 0
   plugins: [
      // enables dragging the slider with mouse/touch
      swipeHandler(),
      // the button plugin uses the querySelector method, hence # at the beginning
      buttons({ nextBtn: "#next", prevBtn: "#prev" })
   ],
});

You can find more examples here

CSS options

By default, modular slider provides two css options. They both require some css variables that you may put either in the :root or .MS-wrapper element.

  1. Width in percentage (default) the outer container has a specified width and the slides subordinate to it

e.g. the container has width set to 30rem or 80% whereas slides have width set to 50%

.your-slider-class.MS-wrapper {
  // you DON'T have to set --number-of-slides - it's just a fallback value just in case something goes wrong
  --number-of-slides: 6; // the number of the slides, total
  --slides-per-view: 2; // the number of how many slides are displayed at once
  --slide-margin: 25px; // the left and right margin of each element
  width: 80%; // add some width
}
  1. Fixed width (add .MS-fixed class) the slides have a specified width - the container subordinates to them

e.g. the container does not have a set width whereas slides have width set to 15rem

.your-slider-class.MS-fixed.MS-wrapper {
  --slide-width: 15rem; // the width of each slide
  --slide-margin: 25px; // the left and right margin of each element
  --slides-per-view: 2; // the number of how many slides are displayed at once
  // don't specify the width - it will be calculated based on the variables above
}

By default --slide-margin is set to 0px.

Contributing

Modular Slider by design encourages users to enhance it. Don't like the event handlers? Want the buttons/pagination to automatically generate themselves? Write a plugin that will do that. If you have created such an improvement, fell free to share it. PRs are welcome! :fire:

Changelog

License