2.0.3 • Published 7 years ago

slider-manager v2.0.3

Weekly downloads
13
License
MIT
Repository
github
Last release
7 years ago

slider-manager

stable

Usage

NPM

npm install slider-manager --save

import Manager from 'slider-manager'
import gsap from 'gsap'

const slides = [].slice.call(document.querySelectorAll('.slides'))

const slider = new Manager({
    length: slides.length,
    loop: true,
    callback: (event) => {
        
        const index = event.current
        const previous = event.previous
        const down = event.direction === 'downwards'

        slider.animating = true

        this.videos[index].play()

        const windowheight = window.innerHeight
        const tl = new TimelineMax({ paused: true, onComplete: () => {

            this.videos[previous].pause()
            slider.animating = false
        }})

        tl.staggerTo(slides, 1, { cycle: {
            y: (loop) => index === loop ? 0 : loop < index ? -windowheight : windowheight
        }, ease: Expo.easeInOut}, 0, 0)

        tl.restart()
    }
})

slider.init()

options

  • el: HTMLElement to listen for scroll/touch events - defaults to document.body
  • direction: 'x' or 'y' - defaults to 'y'
  • loop: true of false - defaults to false
  • delta: delta limiter for scroll/touch events - defaults to 1
  • limitInertia: if set to true, leverage the limitInertia option of virtual-scroll to distinguish between user-initiated and inertial scrolling. Prevents callback from firing multiple times per scroll - defaults to false.
  • callback: function called when user has swiped or scrolled

methods

  • init: add event listeners
  • goTo(index): goes to the slide index
  • destroy: remove event listeners

changelog

  • 1.0.6: added direction to options, so it listens to either deltaX or deltaY depending on the desired option
  • 1.1.6: added limitInertia to options, that when set to true fixes a behavior where multiple callbacks are fired for a single user-initiated scroll due to inertial scrolling.

License

MIT, see LICENSE.md for details.

2.0.3

7 years ago

2.0.2

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.1.5

7 years ago

1.1.4

7 years ago

1.1.3

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

8 years ago

1.0.0

8 years ago