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

touchpad-scroll-carousel

v1.0.3

Published

The simple, lightweight responsive carousel that requires no dependencies and supports scroll on touchpad.

Downloads

21

Readme

Touchpad Scroll Carousel

The simple, lightweight responsive carousel that requires no dependencies and supports scroll (left/right) on touchpad.

Demo

Touchpad Scroll Carousel Example

Install

Markup

HTML would look something like this:

<div id="carousel">
  <div class="item">
    <a href="...">
      <img src="..." alt="..." />
    </a>
  </div>
</div>

You only need a list of item (slide), then initialize the carousel like this:

TouchpadScrollCarousel({
  carouselSelector: "#carousel",
  ... // other options
});

CDN

jsDelivr: https://cdn.jsdelivr.net/npm/touchpad-scroll-carousel/dist/touchpad-scroll-carousel.min.js

Example use CDN:

...
<body>
  <div id="carousel">
    <div class="item">
      <a href="..."><img src="..." alt="..." /></a>
    </div>

    <div class="item">
      <a href="..."><img src="..." alt="..." /></a>
    </div>

    <div class="item">
      <a href="..."><img src="..." alt="..." /></a>
    </div>
  </div>

  <script src="https://cdn.jsdelivr.net/gh/robinhuy/touchpad-scroll-carousel/dist/touchpad-scroll-carousel.min.js"></script>
  <script>
    TouchpadScrollCarousel({
      carouselSelector: "#carousel",
    });
  </script>
</body>

NPM

npm install touchpad-scroll-carousel

or using yarn:

yarn add touchpad-scroll-carousel

Example use NPM for a React App:

import { useEffect } from "react";
import "touchpad-scroll-carousel/dist/touchpad-scroll-carousel.min.js";

const CarouselComponent = () => {
  useEffect(() => {
    window.TouchpadScrollCarousel({
      carouselSelector: "#carousel",
    });
  }, []);

  return (
    <div id="carousel">
      <div className="item">
        <a href="...">
          <img src="..." alt="..." />
        </a>
      </div>

      <div className="item">
        <a href="...">
          <img src="..." alt="..." />
        </a>
      </div>

      <div className="item">
        <a href="...">
          <img src="..." alt="..." />
        </a>
      </div>
    </div>
  );
};

export default CarouselComponent;

If you want to use TypeScript, create a file name index.d.ts in root folder of the project or in same folder as the component:

export {};

interface ResponsiveOptions {
  breakpoint?: number;
  slidesToShow?: number;
  gap?: number;
}

interface TouchpadScrollCarouselOptions {
  carouselSelector: string;
  slidesToShow?: number;
  slidesToScroll?: number;
  gap?: number;
  mouseDrag?: boolean;
  showArrows?: boolean;
  nextButtonSelector?: string;
  prevButtonSelector?: string;
  showScrollbar?: boolean;
  scrollbarStyle?: {
    position?: string;
    height?: number;
    marginTop?: number;
    marginBottom?: number;
    borderRadius?: number;
    backgroundColor?: string;
    thumbColor?: string;
    thumbHoverColor?: string;
  };
  responsive?: ResponsiveOptions[];
}

declare global {
  interface Window {
    TouchpadScrollCarousel: (options: TouchpadScrollCarouselOptions) => void;
  }
}

Settings

| Option | Type | Default | Description | | ------------------ | -------------------------- | ------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------- | | carouselSelector | string (CSS selector) | null | Selects a node to initialize the carousel | | gap | int (value as pixel unit) | 15 | The gap between items | | mouseDrag | boolean | true | Enables mouse dragging | | showArrows | boolean | true | Enables Next/Prev arrows | | nextButtonSelector | string (CSS selector) | #btn-next | Allows you to select a node to customize the "Next" arrow. Only work when showArrows = true. | | prevButtonSelector | string (CSS selector) | #btn-prev | Allows you to select a node to customize the "Previous" arrow. Only work when showArrows = true. | | showScrollbar | boolean | true | Enables scrollbar. | | scrollbarStyle | object | See example | Contains style settings for the scrollbar. Only work when showScrollbar = true. | | responsive | array | null | Array of objects contains breakpoints and setting objects (see example). Enables settings at given breakpoint. | | slidesToScroll | int | 1 | # of slides to scroll at a time | | slidesToShow | float | 1 | # of slides to show at a time |

ScrollbarStyle Option

The scrollbar style options, for example:

TouchpadScrollCarousel({
  carouselSelector: "#carousel",
  scrollbarStyle: {
    position: "bottom", // "top" or "bottom"
    height: 8,
    marginTop: 8,
    marginBottom: 8,
    borderRadius: 4,
    backgroundColor: "#ebebeb",
    thumbColor: "#6d6d6d",
    thumbHoverColor: "#4b4b4b",
  },
});

Note that dimensions are measured in px and colors are in string format (color name, hex value,...).

Responsive Option

The responsive options with self-defined breakpoints, for example:

TouchpadScrollCarousel({
  carouselSelector: "#carousel",
  responsive: [
    {
      breakpoint: 768,
      slidesToShow: 2.5,
      gap: 20,
    },
    {
      breakpoint: 1200,
      slidesToShow: 4,
      gap: 30,
    },
  ],
});

Browser support

Touchpad Scroll Carousel works on modern browsers such as Edge, Chrome, Firefox, and Safari.

License

Copyright (c) 2022 Robin Huy.

Licensed under the MIT license.