0.2.2 • Published 3 years ago

jrd-carousel v0.2.2

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

JrdCarousel

JrdCarousel is a carousel component written 100% in JavaScript.

TOC

  1. Roadmap
  2. Get started
  3. Methods
  4. Parameters

Roadmap

  • Make it work with arrow keys
  • Preload next image
  • Animations

Get started

  1. Install jrd-carousel

    npm i jrd-carousel
  2. Create your carousel

    <!-- index.html -->
    <div id="my-carousel"></div>
    // script.js
    import JrdCarousel from 'jrd-carousel'
    
    const options = {
      images: [
        {
          src: 'https://images.com/image0.jpg',
          alt: 'Image alt 0'
        },
        {
          src: 'https://images.com/image1.jpg',
          alt: 'Image alt 1'
        },
        {
          src: 'https://images.com/image2.jpg',
          alt: 'Image alt 2'
        },
      ]
    }
    
    JrdCarousel('my-carousel', options)

Methods

JrdCarousel()

JrdCarousel(domId: string, options: object)

Parameters

domId

Represents the id of the DOM element where we want to mount the carousel.

options

Holds the settings for the carousel

Properties
  • images: string[] Required Array with image objects. They will be loaded in order

Must have a src attribute and a alt attribute.

__

  • autoplay: boolean Optional Default: true Makes the carousel slide automatically every interval __
  • interval: number Optional Default: 1500 Milliseconds between every slide change __
  • imagesToPreload: number Optional Default: 2 How many images you want to preload when the component is mounted.

    By default the component will load the first 2 images and lazy load the rest when they have to be shown.

  • height: number Default: 360

    The height attribute in the <img> tag.

  • width: number Default: 640 The width attribute in the <img> tag.
// Options example

const options = {
  images: [
      {
        src: 'https://images.com/image0.jpg',
        alt: 'Image alt 0'
      },
      {
        src: 'https://images.com/image1.jpg',
        alt: 'Image alt 1'
      },
      {
        src: 'https://images.com/image2.jpg',
        alt: 'Image alt 2'
      },
    ],
  imagesToPreload: 1,
  interval: 3000
}

About

JrdCarousel is a technical test made by @jordienr for Domestika.

0.2.1

3 years ago

0.2.2

3 years ago

0.2.0

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago

0.0.1

3 years ago