Giter VIP home page Giter VIP logo

iron-transitioner's Introduction

Installation

Just mrt add iron-transitioner. That's it.

Custom Layouts

If you want to use a layout, you can transition a yielded section simply by calling {{transitionedYield}} where you would normally call {{yield}}. You can still continue to use {{yield}} in your layout.

NOTE that due to limitations in IT, you cannot use data in your layout. Hopefully this limitation will be gone with the release of Meteor UI.

How it works

Iron Transitioner places down the following HTML structure:

<div clas="transitioner-panes">
  <div class="left-pane"></div>
  <div class="right-pane"></div>
</div>

Initially, IT will render the page into .left-pane, and will add .current-page to it.

When the page changes, IT will render the new page into .right-pane, mark it as .next-page to it, and then set the class .transitioning to the the .transitioner-panes, as well as some classes indication which templates are being transitioned from and to.

When the transition is over, it will empty the .left-pane, and move the .current-page class to the .right-pane div. On the next transition, it will do the reverse.

You can those changes to easily implement CSS transitions. The package comes with a built in .default transition that slides the next page in from the right.

Custom CSS

The built in CSS that's installed with IT might not work with your layout, or perhaps you want to do a different style of transition.

To start, take a look at transitioned_default_layout.less to see how it works, and override the CSS as you will.

IMPORTANT: You need to have a "null" transition on the .transitioner-panes to inform IT when the transition is over. The built in default transition uses a delayed opacity transition to achieve this.

NOTE: If you don't want to fight the built in styles, just rename the default transition using Router.transitionType() (see the next section).

Custom transition types

You can use:

Router.transitionType(function(fromTemplate, toTemplate) {});

to set the type of the transition based on the templates being used.

This type will be added to the .transitioner-panes, along with .from-X and .to-Y (where X and Y are the names of the templates being transitioned).

Some examples:

If you want to reverse the transition when the user hits a "back" button in your app, you could write:

var nextTransition = 'default';

Template.X.events({
  'click .back': function() {
    nextTransition = 'back';
    history.back();
  }
});

Router.transitionType(function() {
  var nt = nextTransition;
  nextTransition = 'default';
  return nt;
});

If you want two pages to have a special transition, you could do:

Router.transitionType(function(from, to, type) {
  if (from === 'templateOne' && to === 'templateTwo') {
    return 'special';
  }
  return type;
});

Of course, you might be better off just doing (and not polluting your JS with presentation code):

.transitioner-panes.transitioning.from-templateOne.to-templateTwo {
  // special transition CSS
}

Cancelling a transition

If you return false from your transition type function, the transition will cancel, and IT will redraw the next template in the same pane. This allows things like preserve to work for instance.

Contributing

Contributions are very welcome. One thing that could be cool would be a bunch of built in transitions, although I don't know a general way to make them work with all layouts.

License

MIT. (c) Percolate Studio

iron-transitioner's People

Contributors

tmeasday avatar

Watchers

James Cloos avatar  avatar

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.