2.1.0 • Published 4 years ago

scroll-slide v2.1.0

Weekly downloads
9
License
MIT
Repository
github
Last release
4 years ago

Build Status npm version

scroll-slide

Flexible and pure-js scrollable slides maker.

demo

Features

  • No other requirements like jquery.
  • Can make onepage-scroll and also section-scroll.
  • Add or remove slides programatically.
  • Both scrolling and swiping are supported.
  • Keyboard supported.
  • Optional paginator.

Usage

Install the library via npm:

npm install scroll-slide

Usage in HTML:

<script src="/path/to/scroll-slide.min.js"></script>

Or using es6:

import Scroll from 'scroll-slide'

Basic examples

const scroll = new Scroll({
  viewport: document.getElementById('viewport'),
  slides: document.querySelectorAll('#viewport section'),
  paginator: 'right',
  onScroll (i) {
    alert(`This is slide ${i + 1}`)
  }
})

Full mode

You can create slide which fills the entire viewport regardless of its original size by setting attribute data-full to 'true'.

<div id="viewport">
  <section id="full" data-full="true">
    This slide will fill the entire viewport.
  </section>
  <section id="nofull">
    This slide will keep its original size.
  </section>
</div>

API

Methods

constructor(option)

More for option, see below.

add(el, index)

Adds new element to viewport at position index. Push to the end by default.

current()

Returns the index of current slide. Starts from 0.

remove(index)

Removes the element at position index in the viewport.

scrollDown()

Moves the slide down by one. The same as scrolling down/swiping down.

scrollTo(index = 0)

Moves to the slide at position index. Moves to the first slide by default.

scrollUp()

Moves the slide up by one. The same as scrolling up/swiping up.

toggleFull(el)

Toggles full mode of an element.

Options

PropertyDescriptionTypeDefault
autoHeightIf true, the height of slides will be responsive to the height of window.Booleantrue
dotColorThe color for paginator dots.String'#e1e1e1'
dotActiveColorThe color for paginator dot which is currently actived.String'#6687ff'
durationHow long the scolling animation will last in milliseconds.Number1000
idleTimeHow long the browser won't respond to the scrolling action after last scrolling in millseconds.Number200
loopIf the continuous loop mode to be enabled.Booleantrue
keyboardIf true, you can use up/down and pageUp/pageDown to navigate slides.Booleantrue
paginatorIf 'none', there will be no paginator. If 'right'/'left', the paginator will be shown on the right/left of the viewport.String'none'
slidesThe elements to be shown as slides in the viewport.Array[]
viewportThe wrapper element for all slides. If you need to create a onepage-scroll website, just set viewport to fit the screen size.Elementnull
onScrollThe callback function when reaches a new slide. The index of current slide will be passed.Functionnull
2.1.0

4 years ago

2.0.2

4 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.5.4

6 years ago

0.5.3

6 years ago

0.5.2

6 years ago

0.5.1

6 years ago

0.5.0

6 years ago

0.4.1

6 years ago

0.4.0

6 years ago

0.3.0

6 years ago

0.2.3

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago