Choreograph elegant, performant exit animations on the web. This library is design from a "less is more" additude in regards to JavaScript code. Animations are expected to be implemented separately, using pure CSS transitions & animations.
<!-- 1. Include the pangea.js library -->
<script src="pangea.min.js"></script>
<!-- 2. Tag an element as being the last to animate, using any ID you see fit -->
<h1>Test webpage</h1>
<p><a href="/about">More about me</a></p>
<p id="last-to-animate">This element is last to animate</p>/*
* Example default styles.
*/
body {
backgrond-color: white;
/* We use CSS transitions to create the animations. */
transition: 0.3s ease background;
}
h1, p {
opacity: 1;
transition: 0.3s ease opacity;
}
/*
* Example animation styles.
*
* Here, we fade out text and fade the background to black when the
* Pangea library gives the body the animating-to-about-page class.
*/
body.animating-to-about-page {
background-color: black;
}
body.animating-to-about-page h1,
body.animating-to-about-page p {
opacity: 0;
}/*
* When we click links to the /about page, the library gives the body the
* animating-to-about-page class. When the element with ID last-to-animate
* is done transitioning, we will navigate to the /about page.
*/
var pangea = new Pangea()
.register(/\/about/, 'last-to-animate', 'animating-to-about-page')
.enable();The Pangeaconstructor will setup a new page animation manager instances. Returns a new instance of the Pangea class.
You can customize the instance by passing the options parameter. The example below uses all options and their defaults:
var opts = {
shouldScroll: true,
scrollTiming: 'before',
animateLinksToSelf: true,
computeScrollOffset: function() { return 0; },
shouldAnimate: function() { return true; },
beforeAnimationStart: function() {},
onTransitionEnd: function() {},
};
var pangea = new Pangea(opts)Type:
ObjectDefault: See below
Description: Configuration options.
Type:
boolDefault: true
Description: Whether or we should scroll the page as part of the animation.
Type:
stringDefault:
"before"Description: The defualt scroll timing. One of:
"before": scroll the page before starting animations"during": scroll the page and start the animations at the same time"after": scroll once the animations are complete
Type:
boolDefault:
trueDescription: Whether or not links to the current page should be ignored.
Type:
functionDefault:
function() { return 0; }Description: A function to compute the offset from the top of the page to scroll to as a part of the animation.
Type:
functionDefault:
function() { return true; }Description: A function to compute whether or not we should animate.
Type:
functionDefault:
function() {}Description: A function to run before the animation starts.
Type:
functionDefault:
function() {}Description: A function to run once the animation is complete.
Register a new animation on this page.
Type:
stringDescription: The pattern to be passed to
new RegExp()to match the URL paths that this animation should apply to.
Type:
stringDescription: The ID of the element that is last to transition. We listen to the transitionEnd event on this element to know when to navigate to the next page.
Type:
stringDescription: The class to apply to the body to start the animations.
Type:
ObjectDescription: Configuration options
Type:
boolDefualt: The value of
options.shouldScrollpassed intoPangea().Description: Whether or not we should scroll the page as part of this animation.
Type:
boolDefault: the value of
options.scrollTimingpassed intoPangea().Description: The scroll timing for this animation
Options:
"before": scroll the page before starting animations"during": scroll the page and start the animations at the same time"after": scroll once the animations are complete
Deregisters the animation for the passed urlRegex. Returns the Pangea instance.
Type:
stringDescription The same pattern that was passed into
Pangea.register().
Enable the Pangea library by beginning to listen to click events, running animations appropriately.
Disable the Pangea library by removing event listeners set in Pangea.enable().
