Giter Site home page Giter Site logo

johnthad / helium-animated-pages Goto Github PK

View Code? Open in Web Editor NEW

This project forked from alangdm/helium-animated-pages

0.0 1.0 0.0 480 KB

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

Home Page: https://helium-animated-pages.glitch.me/demo/

License: BSD 3-Clause "New" or "Revised" License

JavaScript 99.46% HTML 0.54%

helium-animated-pages's Introduction

<helium-animated-pages>

Published on webcomponents.orgnpm version

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:

    <!-- type="module" 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 0.7s ease both;
      }
      @keyframes fadeIn {
        from {
          opacity: 0.3;
        }
        to {
        }
      }
      .page-fadeOut {
        animation: fadeOut 0.7s ease both;
      }
      @keyframes fadeOut {
        from {
        }
        to {
          opacity: 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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.