0.3.0 • Published 4 years ago

@chaucerbao/reveal.js v0.3.0

Weekly downloads
26
License
ISC
Repository
-
Last release
4 years ago

Reveal.js · npm bundle size (minified)

Reveal elements one at a time while the user scrolls through your site.

Note: This library uses Intersection Observer, so a polyfill may be required for some browsers.

Usage

Add the data-reveal attribute to individual elements you want animated as the user scrolls. Group those elements into a container. When the container crosses a certain threshold the data-reveal elements inside will be revealed, one at a time.

<!-- HTML -->
<section class="container">
  <h1 data-reveal>Amazing title</h1>
  <p data-reveal>Very intriguing content.</p>
  <button data-reveal>Do the thing</button>
</section>

Initialize reveal() with customizable options.

/* JavaScript */
reveal({
  elements: document.querySelectorAll('.container'),
  prepend: document.querySelectorAll('header'), // Prepended elements animate on-load
  interval: 750, // Elements will be revealed on a 750ms interval
  rootMargin: '-15% 0%', // Begin revealing when a container is 15% into the viewport
})

Now, define your reveal animation with CSS.

/* CSS */

/* Initial, hidden state */
[data-reveal] {
  transform: translateY(20%);
  opacity: 0;

  transition: opacity 1s, transform 1s;
}

/* Final, revealed state */
[data-reveal='revealed'] {
  transform: translateY(0);
  opacity: 1;
}

Options

Available options for reveal(options).

OptionTypeDefaultDescription
elementsElement[]RequiredAn array of container elements that will be observed
prependElement[][]An array of container elements that will be revealed immediately after initialization
intervalnumber100Interval (in milliseconds) between each reveal
rootMarginstring'0px 0px 0px 0px'Offset applied to the viewport for calculating an intersection (MDN)
0.3.0

4 years ago

0.2.0

4 years ago

0.1.4

5 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