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

image-carousel-forkfiesta

v1.0.1

Published

A simple carousel package that loads images and displays them as a carousel

Downloads

18

Readme

Image Carousel

A simple, lightweight JavaScript package to create a customizable image carousel with navigation controls and dot indicators. This package allows you to load images from a specified directory and navigate through them with next/previous buttons and dot indicators.

Features

  • Dynamically loads images from a specified directory.
  • Supports navigation through next/previous buttons.
  • Provides dot indicators for direct navigation to specific images.
  • Lightweight and easy to customize.

Installation

Clone this repository and include the necessary files in your project.

git clone https://github.com/your-username/image-carousel.git

Or, if published as an npm package, you can install it via npm:

npm install image-carousel

Usage

1. Include HTML Structure

Add the following structure to your HTML file. The .carousel-image elements will be dynamically populated with images, and the .prev, .next, and .dot elements enable navigation.

<div class="slideshow-container">
  <div class="slides fade">
    <div class="numberText">1/6</div>
    <img class="carousel-image" src="#" style="width: 100%;" />
    <div class="text">Caption Text</div>
  </div>
  <!-- Repeat .slides elements as needed, each with an empty .carousel-image element -->

  <a class="prev">&#10094;</a>
  <a class="next">&#10095;</a>
</div>

<div class="dot-circles">
  <span class="dot"></span>
  <!-- Repeat .dot elements as needed for each slide -->
</div>

2. Add CSS

To style the carousel, add the provided styles.css file, or customize it according to your needs. This file includes styles for the slideshow container, navigation buttons, and dot indicators.

3. Import and Initialize the Carousel

In your main JavaScript file, import the carousel functions and initialize them. Update the image path as needed.

import { createImageArray, createCarousel } from "./image-carousel.js";

createImageArray("./img/", (imgArray) => {
  const carousel = createCarousel(imgArray);
  carousel.showSlides();

  // Event listeners for navigation buttons
  document
    .querySelector(".prev")
    .addEventListener("click", () => carousel.plusSlides(-1));
  document
    .querySelector(".next")
    .addEventListener("click", () => carousel.plusSlides(1));

  // Event listeners for dot indicators
  document.querySelectorAll(".dot").forEach((dot, index) => {
    dot.addEventListener("click", () => carousel.currentSlide(index + 1));
  });
});

Configuration

Image Directory

Specify the directory where your images are located when calling createImageArray. Ensure the images are named sequentially as follows: image1.jpg, image2.jpg, etc.

HTML Classes

  • .carousel-image: Image placeholders to be populated by the carousel.
  • .slides: Container for each individual slide, holding an image and optional caption text.
  • .prev & .next: Navigation buttons for moving through the carousel slides.
  • .dot: Dot indicators for direct navigation to each slide.

JavaScript Functions

  1. createImageArray(imgFolderPath, callback):

    • Loads images from the specified imgFolderPath and adds them to an array.
    • Calls the callback function with the image array after loading.
  2. createCarousel(imgArray):

    • Accepts an array of image URLs and returns an object with methods to control the carousel:
      • showSlides(): Displays the current slide.
      • plusSlides(n): Moves to the next or previous slide.
      • currentSlide(n): Jumps directly to a specific slide.

Example

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Image Carousel</title>
    <link rel="stylesheet" href="styles.css" />
    <script type="module" src="index.js"></script>
  </head>
  <body>
    <div class="slideshow-container">
      <!-- Example slide -->
      <div class="slides fade">
        <div class="numberText">1/3</div>
        <img class="carousel-image" src="#" style="width: 100%;" />
        <div class="text">Caption Text</div>
      </div>

      <!-- Navigation buttons -->
      <a class="prev">&#10094;</a>
      <a class="next">&#10095;</a>
    </div>

    <!-- Dot indicators -->
    <div class="dot-circles">
      <span class="dot"></span>
      <span class="dot"></span>
      <span class="dot"></span>
    </div>
  </body>
</html>

License

This project is licensed under the MIT License.