Directory

← Back

helium-animated-pages

A light spiritual succesor to neon-animated-pages using only css animations

Author

Rating

Popularity

<100

<helium-animated-pages>

Published on webcomponents.orgnpm version

API | Demo | Using it in pwa-starter-kit

This is a light spiritual successor to the now deprecated <neon-animated-pages>.

It works with css animations and only depends on lit-element so you don't have to worry about including any heavy js libraries.

This component takes care of the logic behind triggering the animations so that you can focus on making your views and your animations (or just use the animations included in the sample-animations folder if you don't want to bother with those either �.)

It can be easily used in pwa-starter-kit and here's how.

To begin using it just follow this simple steps:

  • Install it:

    npm i --save helium-animated-pages

  • Import the script:

    In html:

      <!-- Don't forget to include webcomponents loader -->
      <script src="node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>
      <!-- type="moodule" is essential -->
      <script type="module" src="node_modules/helium-animated-pages/helium-animated-pages.js"></script>
    

    In a js module:

      import 'helium-animated-pages/helium-animated-pages.js';
    
  • Create an instance of <helium-animated-pages> in your HTML page, or via any framework that supports rendering Custom Elements and start using it:

      <style>
        /* define your animation keyframes and classes
          (you can use the ones provided too)
          these must be defined context that contains
          <helium-animated-pages> */
        /* these only use the standard css animation to keep
         example code short */
        .page-fadeIn {
            animation: fadeIn .7s ease both;
        }
        @keyframes fadeIn {
            from { opacity: 0.3; }
            to { }
        }
        .page-fadeOut {
            animation: fadeOut .7s ease both;
        }
        @keyframes fadeOut {
            from { }
            to { opacity: 0.0; }
        }
      </style>
      <section>
        <h2>Select a page</h2>
        <select id="selector">
          <option value="page1">Page 1</option>
          <option value="page2">Page 2</option>
          <option value="page3">Page 3</option>
        </select>
      </section>
      <!-- attrForSelected is used to say which attribute
        identifies the pages
        or you can just not use it and use numerical indexes -->
      <helium-animated-pages id="pages" attrForSelected="name">
        <!-- The pages can be almost anything -->
        <section name="page1">Page 1</section>
        <div name="page2">Page 2</div>
        <!-- It is recommended that custom elements
          used as a page all extend an element like pwa-starter-kit's
          page-view-element
          https://github.com/Polymer/pwa-starter-kit/blob/master/src/components/page-view-element.js
        -->
        <custom-element name="page3"></custom-element>
      </helium-animated-pages>
      <script>
        // example way of changing pages, you could use a router
        // or any other way you want
        document.querySelector('#selector').addEventListener('change',
        (e)=>{
          // Change selected page, can also receive and index
          document.querySelector('#pages').select(e.target.value);
          // you can also use selectPrevious() or selectNext()
        });
    
        // defining the "rules" for which css classes to apply on
        // diferent page transitions, for more info go to:
        // https://github.com/alangdm/helium-animated-pages/wiki/API#attrforselected
        // I'm using css classes which aren't defined on this context but you
        // must define them when actually using this
        document.querySelector('#pages').animationClasses = {
          // animation classes rules are like css rules, the most specific ones apply first
          // from page1 to page2
          'page1_page2': {
            in: 'page_moveFromRight',
            out: 'page_moveToLeft'
          },
          // from anything (other than page1 to page2)
          '*_page2': {
            in: 'page_moveFromLeft',
            out: 'page_moveToRight'
          },
          // from page1 to anything (other than page2)
          'page1_*': {
            in: 'page_moveFromTop',
            out: 'page_moveToBottom'
          },
          // from nothing selected to page1
          '_page1': {
            in: 'page_moveFromBottom',
            out: 'page_moveToTop'
          },
          // if none of the rules above apply
          default: {
            in: 'page-fadeIn',
            out: 'page-fadeOut'
          }
        };
      </script>
    

Credits

Almost all sample animations and the overall flow of the page selection are based on an article by Pedro Botelho@Codrops.

Compatibility

(Loading compatibility data...)

Was this helpful? Need more help?
Leave a comment or a question below. You can also join the chat on Discord or ask questions on StackOverflow.

Version

Dependencies

  • lit-element#^2.0.1
Released
2019-02-25
Maturity
IMPORTED
License
BSD 3-clause "New" or "Revised" License

Compatibility

Framework
Browser
Browser Independent

helium-animated-pages - Vaadin Add-on Directory

A light spiritual succesor to neon-animated-pages using only css animations helium-animated-pages - Vaadin Add-on Directory
# `` [![Published on webcomponents.org](https://img.shields.io/badge/webcomponents.org-published-blue.svg)](https://www.webcomponents.org/element/helium-animated-pages)[![npm version](https://badge.fury.io/js/helium-animated-pages.svg)](https://badge.fury.io/js/helium-animated-pages) ###### [API](https://github.com/alangdm/helium-animated-pages/wiki/API) | [Demo](https://helium-animated-pages.glitch.me/demo/) | [Using it in `pwa-starter-kit`](https://github.com/alangdm/helium-animated-pages/wiki/Usage-in-pwa-starter-kit) This is a light spiritual successor to the now deprecated [``](https://www.webcomponents.org/element/PolymerElements/neon-animation/elements/neon-animated-pages). It works with css animations and only depends on [lit-element](https://github.com/Polymer/lit-element) so you don't have to worry about including any heavy js libraries. This component takes care of the logic behind triggering the animations so that you can focus on making your views and your animations (or just use the animations included in the `sample-animations` folder if you don't want to bother with those either �.) It can be easily used in [pwa-starter-kit](https://github.com/Polymer/pwa-starter-kit/) and [here's how](https://github.com/alangdm/helium-animated-pages/wiki/Usage-in-pwa-starter-kit). To begin using it just follow this simple steps: - Install it: `npm i --save helium-animated-pages` - Import the script: In html: ```html ``` In a js module: ```javascript import 'helium-animated-pages/helium-animated-pages.js'; ``` - Create an instance of `` in your HTML page, or via any framework that [supports rendering Custom Elements](https://custom-elements-everywhere.com/) and start using it: ```html

Select a page

Page 1
Page 2
``` ## Credits Almost all sample animations and the overall flow of the page selection are based on an article by [Pedro Botelho@Codrops](https://tympanus.net/codrops/2013/05/07/a-collection-of-page-transitions/).
Online