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

@signalchain/looped

v0.0.1

Published

A 3kb Vanilla JS Carousel that scales with the browser.

Downloads

1

Readme

Maintenance Status NPM JavaScript Style Guide

"Looped" Carousel

The "bring your own styles", responsive/dynamic carousel for JavaScript. See examples in the github.

Exposes handy methods like .next() and .prev() on elements that can be easily wired to event handlers in the onInit method.

An easy to configure object syntax allows you to override defaults setting with one line of code. (See defaults in the table below or in the examples.)

looped demo

Installation

npm install looped

or

yarn add looped

<div class="carousel">
  <div>slide 1</div>
  <div>slide 2</div>
  <div>slide 3</div>
  <div>slide 4</div>
</div>
import Carousel from 'looped';

// Will initialize with default settings
new Carousel({
  selector: '.carousel'
});

Default settings

new Carousel({
  selector: '.carousel',
  transitionDuration: 450,
  easing: 'ease-out',
  perPage: 1,
  gap: 0,
  startIndex: 0,
  draggable: true,
  multipleDrag: true,
  threshold: 20,
  loop: true,
  animate: true,
  intervalDuration: 4250,
  rtl: false,
  onInit: () => {},
  onChange: () => {},
  destroy: () => {},
});

Responsive slide count

Pass an object to perPage and prefix window width with w. Since the default is 1, the properties are applied from narrowest window width to widest window width.

const selector = '.carousel';
const carousel = document.querySelector(selector);
const config = {
  ...
  perPage: {
    // Falls back to the default of 1 below 750px
    w750: 3,
    w1200: 5,
    w1400: 6,
  },
  ...
}

const initCarousel = carousel &&
  new Carousel({
    selector,
    ...config,
  })

// Grab your buttons from the DOM
const prev = document.querySelector('.prev')
const next = document.querySelector('.next')

prev.addEventListener('click', () => {
  initCarousel.prev()
})

next.addEventListener('click', () => {
  initCarousel.next()
})

initCarousel()

Available properties

Prop | Data Type | Default | Required | Description ------------------- | ---------- | --------- | ------- | ----------- selector | String | N/A | true | Enable selector transitionDuration | Number | 450 | false | The time (in ms) between when the slide chip starts it's transition, to when it finishes moving. easin | String | ease-out| false | The "ease" value on the transition property. perPage | Number or Object | 1 | false | The number of slides to be shown per page. See example for responsive carousel. gap | Number | 0 | false | The space between slides. startIndex | Number | 0 | false | The index of the starting index draggable | Boolean | true | false | Use dragging and touch swiping multipleDrag | Boolean | true | false | Allow dragging to move multiple slides. threshold | Number | 20 | false | How far you have to swipe/drag (in px) to go to the next slide. loop | Boolean | true | false | Enable slides to loop. animate | Boolean | true | false | Auto-play slides on load. intervalDuration | number | 4250 | false | The amount of time between next slide call. rtl | Boolean | false | false | Enables layout for languages written from right to left. onInit | Function | | false | Runs immediately after initialization. onChange | Function | | false | Runs after slide change. destroy | Function | | false | Runs when carousel is unmounted.

Common Gotchas

Gap throws off my image spacing. What gives?

Solution: Add this to your CSS

html {
  box-sizing: border-box;
}

*, *:before, *:after {
  box-sizing: inherit;
  margin: 0;
  padding: 0;
}

How to contribute

If you have unanswered questions, would like help with enhancing or debugging the plugin, reach out @ jameygleason.com.

Please see CONTRIBUTING for details.

Credits

This carousel would not be possible without the fine work done on Siema.

NPM

https://www.npmjs.com/package/looped

License

The MIT License (MIT). Please see License File for more information.