0.2.5 • Published 3 months ago

@e-scape/slider v0.2.5

Weekly downloads
-
License
ISC
Repository
github
Last release
3 months ago

Slider

Library for creating various sliders and scrolls.

Setup

The library uses custom elements, and to have them registered, you need to import the library into your project like this:

import '@e-scape/slider'

Markup

Your markup will look like this almost every time:

<!-- Mandatory element. Viewport -->
<x-slider>
  <!-- Mandatory element. Scrollable part -->
  <slider-content>
    <!-- 
      Optional element, but required if the slider is sectional or infinite.
    -->
    <slider-item></slider-item>
    <slider-item></slider-item>
    <slider-item></slider-item>
    <slider-item></slider-item>
    <slider-item></slider-item>
  </slider-content>
</x-slider>

Settings

All slider configuration, for convenience, is placed in CSS and responds to any media queries.

x-slider {
  /* 
    Slider type. 

    Default is 'slide'.
  */
  --type: slide | morph;

  /* 
    Distance between slides. 

    Works only if --type: slide.

    Value can be a number or CSS unit (10vw, 10vh, 10px...).

    Default is 0.
  */
  --gap: number | CSS unit;

  /* 
    Automatic scrolling.

    If the slider scrolls freely, 
    the value specified in this parameter is added every frame.
    If the slider is sectional, a transition to the next slide will occur 
    after the specified number of milliseconds.

    Default is 0.
  */
  --autoplay: number;

  /*
    Scroll smoothness.

    Works only if --type: slide.

    Default is 0.01.
  */
  --damping: number;

  /*
    Makes the slider infinite.

    <slider-item> elements must be present in the markup.

    Default is false.
  */
  --carousel: boolean;

  /*
    Scroll direction. 

    Works only if --type: slide.

    Default is 'x'.
  */
  --axis: x | y;

  /*
    Sectional scrolling. 

    Works only if --type: slide.

    Default is false.
  */
  --snap: boolean;

  /*
    Automatic slide size.

    Works only if --type: slide.

    Default is false.
  */
  --autoFill: boolean;

  /*
    Number of visible slides.

    Complements the previous parameter.

    Works only if --type: slide.

    Default is 1.
  */
  --itemsInView: number;

  /*
    Gesture control.

    Default is false.
  */
  --drag: boolean;

  /*
    Gesture acceleration.

    Default is 1.
  */
  --dragMult: number;

  /*
    Mouse wheel control.

    Default is false.
  */
  --wheel: boolean;

  /*
    Mouse wheel acceleration.

    Default is 1.
  */
  --wheelMult: number;

  /*
    Keyboard control.

    Default is false.
  */
  --keys: boolean;
}

Public API

TODO

import '@e-scape/slider'
import { SliderElement } from '@e-scape/slider'

const element = document.querySelector<SliderElement>('x-slider')!

element.progress
element.direction
element.speed
element.isRunning
element.directionSize
element.directionScrollSize
element.directionScrollLimit
element.isDisabled
element.disable()
element.enable()
element.range(0, 1, 0)
element.curve(0, 1, 0)
element.visible(0, 1, 0)
element.setPosition(100, 'instant' | 'smooth')
element.shiftPosition(100, 'instant' | 'smooth')
element.setCounter(3, 'instant' | 'smooth')
element.shiftCounter(1, 'instant' | 'smooth')
const unsubscribe = element.onPosition(({ current, previous }) => {})
0.2.3

3 months ago

0.2.5

3 months ago

0.2.4

3 months ago

0.2.1

3 months ago

0.2.0

3 months ago

0.2.2

3 months ago

0.1.42

3 months ago

0.1.41

3 months ago

0.1.40

3 months ago

0.1.31

3 months ago

0.1.32

3 months ago

0.1.33

3 months ago

0.1.35

3 months ago

0.1.36

3 months ago

0.1.37

3 months ago

0.1.27

3 months ago

0.1.28

3 months ago

0.1.29

3 months ago

0.1.38

3 months ago

0.1.39

3 months ago

0.1.25

4 months ago

0.1.26

4 months ago

0.1.24

4 months ago

0.1.20

4 months ago

0.1.21

4 months ago

0.1.22

4 months ago

0.1.23

4 months ago

0.1.16

4 months ago

0.1.17

4 months ago

0.1.18

4 months ago

0.1.19

4 months ago

0.1.14

4 months ago

0.1.15

4 months ago

0.1.10

4 months ago

0.1.11

4 months ago

0.1.12

4 months ago

0.1.13

4 months ago

0.1.9

4 months ago

0.1.8

4 months ago

0.1.8-r

4 months ago

0.1.7

4 months ago

0.1.6

5 months ago

0.1.5-1

5 months ago

0.1.4

5 months ago

0.1.5

5 months ago

0.1.3

5 months ago

0.1.2

5 months ago

0.1.1

5 months ago