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

progressive-carousel

v1.6.2

Published

A mobile friendly and progressive enhanced image carousel

Downloads

21

Readme

Progressive Carousel

A mobile friendly and progressive enhanced image carousel

Demo

Screenshot

Features

  • Responsive and mobile-friendly
  • Fullscreen mode
  • Touch gestures and mouse dragging
  • Accessible with keyboard and screen reader
  • Clean and semantic HTML
  • Works with images of any size
  • Hardware accelerated animations (using CSS transform)
  • Lightweight (~10kb minified)
  • No JQuery dependency
  • Browser support:
    • Browsers supporting classList and CSS transforms: basically IE10+ and all modern browsers.
    • On older browsers (and while JavaScript is loading), the browser will render an ordinary grid of images. Clicking an image will open the high resolution image.

About

Progressive Carousel has a consistent user experience across different screen sizes, and on portrait/landscape orientation: there is no predefined amount of images for each breakpoint.

On smaller screens, a tiny bit of the next and previous image is visible. This gives the user a hint that he can swipe the images left and right.

Swiping is implemented using the Touch API (and not the more generic, but less supported, Pointer Events API). When your browser doesn't support the Touch API, you can still control the carousel with the buttons.

On larger screens, more images are visible in the image strip. Although the carousel can be nested inside a single column layout, it is recommended to show the images on full width of the page, maximizing available screen space.

The next/previous buttons and the first image in the strip are focusable with the keyboard (TAB key). Opening the first image with the keyboard will toggle fullscreen mode. While in fullscreen mode, users can press ESC to exit and the arrow keys (← →) to cycle through the images.

The carousel uses the Fullscreen API. For browsers not supporting the Fullscreen API, the carousel will be shown in 100% width/height of the browser window.

Requirements

Installation

Get started by adding the following HTML to your page.

  • Data-attributes (e.g. data-carousel) are used by JavaScript to interact with the DOM. Keep them.
  • Classes are only used for styling. Customize them as you like.

HTML

<div class="carousel" data-carousel>
    <button class="carousel-close" 
            data-carousel-close>Close</button>
    <button class="carousel-previous" 
            data-carousel-previous
            aria-label="Previous"></button>
    <ul class="carousel-list" 
        data-carousel-list>
        <li class="carousel-item" data-carousel-item>
            <a class="carousel-anchor" 
               href="image-xl.jpg"
               data-carousel-anchor>
                <img class="carousel-img" 
                     src="image-m.jpg"
                     srcset="image-s.jpg 300w,
                             image-m 600w,
                             image-l.jpg 968w,
                             image-xl.jpg 1920w"
                     sizes="(min-width: 1170px) 968px, 85vw"
                     alt="Example image 1"
                     data-carousel-img>
            </a>
        </li>
        <!-- <li>'s for remaining images here -->
    </ul>
    <button class="carousel-next"
            data-carousel-next 
            aria-label="Previous"></button>
</div>

Explanation:

  • <a>
    • href: url of high resolution image.

      This allows the user to navigate to the high resolution image when the carousel is not enhanced with JavaScript. When? While JavaScript is loading, on browsers not meeting the minimum criteria or when JavaScript is disabled. Everyone has Javascript, right?

  • <img>
    • src: url of the fallback image for browsers not supporting 'srcset'.
      • In fullscreen mode, the carousel will replace the src value with the url of the image with the highest resolution (as specified in srcset). This allows browsers not supporting srcset to still show high resultion images in fullscreen mode.
    • srcset: list of responsive images and their natural width, so that browsers can choose the appropriate image (srcset and sizes explanation).
      • The example lists 4 images, but any number works. The browser will choose to load an image based on resolution and device-pixel-ratio. Providing enough images can save the user precious time and bandwidth.
      • The example lists 300w, 600w, 968w and 1920w as natural widths, but the carousel accepts images with any natural width.
    • sizes: width of the image when the condition matches.
      • In the example we tell the browser to show each image at 85vw width, except for breakpoints above 1170px, in which case the browser should render the image at 968px width. This means you don't have to configure the exact number of visible images per breakpoint.
      • In fullscreen mode, the carousel will set the sizes attribute value to 100vw, so that the browser can choose the appropriate fullscreen image. When fullscreen is closed, the sizes attribute is restored to the original value.

CSS

You can find boilerplate CSS here to get you started.

Typical things you may want to customize:

  • the speed and type of animations
  • next/previous/close button styles
  • layout of the thumbnails when the carousel is not enhanced with JavaScript.

The CSS file contains vendor prefixes. Consider using a build system with autoprefixer to add them automatically.

JavaScript

  1. First, import the JavaScript module:
import Carousel from 'progressive-carousel';
  1. Then initialize all carousels (more than 1 is allowed):
Carousel.initializeAll();

When the carousel has been initialized, the images should be positioned side by side (like a 'film strip') and no longer in a grid.

By default, all carousels on the page are initialized. Optionally, you can provide a DOM element to scope the context where carousels appear in, e.g.:

// initialize all carousels inside `#sidebar`
const sidebar = document.getElementById('sidebar');
Carousel.initializeAll(sidebar);

Future

  • Lazy loading of images
  • Loading indicator (in particular in fullscreen)

Not planned:

  • Captions
  • Breadcrumbs / circles / progress indicators

Author

Created and maintained by reinout.com

Resources

  • https://www.html5rocks.com/en/mobile/touch/
  • https://www.html5rocks.com/en/mobile/touchandmouse/