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

carousel-js

v4.0.0

Published

Easily implement a dynamic carousel using minimal javascript. Supports Meteor, AngularJS, React, Polymer and any CSS library, e.g. Bootstrap.

Downloads

98

Readme

Build Status npm version

Carousel

A lightweight and flexible Carousel class that allows you to build fully functional, advanced Carousels with minimal javascript and markup. This library is built using native vanilla javascript (for performance) and adheres to latest ECMAScript specs. Supports IE10+, all major browsers and even mobile.

Inspiration

This is a module that I built originally to solve many of the headaches and complexities around building flexible and scalable carousels.

This library has been used and adopted on many projects, including:

Installation

You can install as an npm package if using a build system like Browserify.

npm install carousel-js --save-dev

Usage

Carousel

You can create a carousel based off of a set of predetermined markup. Assuming you have the appropriate elements already in the DOM and have your CSS set up correctly to show and hide the styles. You can setup Carousel and navigate to panels programmatically.

var carousel = new Carousel({
    panels: document.getElementsByClassName('carousel-panel')
});

carousel.goTo(1); // go to second carousel panel

Carousel with Clickable Thumbnails

Create a carousel with thumbnails based off of a set of predetermined markup. Assuming, you have your html in the DOM and CSS set up correctly. You can use the Carousel class to add interactivity:

var thumbnails = document.getElementsByClassName('carousel-thumbnail');

var carousel = new Carousel({
    panels: document.getElementsByClassName('carousel-panel'),
    thumbnails: thumbnails
});

// click on second thumbnail to show second panel
thumbnails[1].click();

More details and example can be found here.

Carousel Image Lazy Loading

The carousel class also allows lazy loading images so that you can ensure that large image assets only load when transitioning to the panel they reside in. This saves us from hogging the user's bandwidth and downloading all image assets before a user navigates to it. To use the lazy loading functionality, let's assume you have the following in the DOM already:

<div class="carousel-panel">
    <img data-lazy-src="http://www.gstatic.com/webp/gallery/1.jpg" src="" />
</div>
<div class="carousel-panel">
    <img data-lazy-src="http://www.gstatic.com/webp/gallery/2.jpg" src="" />
</div>

Then you can do this:

var carousel = new Carousel({
    panels: document.getElementsByClassName('carousel-panel'),
    panelActiveClass: 'carousel-panel-active',
    lazyLoadAttr: 'data-lazy-src',
    assetLoadingClass: 'image-loading'
});

// go to second panel and lazy load the image it contains
carousel.goTo(1);

A more in-depth, working example of Carousel's lazy loading can be found here.

Carousel with Arrows

You can easily create a carousel with the traditional left and right arrows. Assuming you have the following markup and styles in the DOM, you can do something like this:

var leftArrowElement = document.getElementsByClassName('carousel-left-arrow')[0];
var rightArrowElement = document.getElementsByClassName('carousel-right-arrow')[0];

var carousel = new Carousel({
    panels: document.getElementsByClassName('carousel-panel'),
    leftArrow: leftArrowElement,
    rightArrow: rightArrowElement,
    arrowDisabledClass: 'arrow-disabled'
});

// go to first panel which will add a css class on the left arrow to disable it
carousel.goTo(0);

// click right arrow to navigate to next panel
// which will remove the disabled css class from the left arrow
rightArrowElement.click();